Skip to content

GsonBuilder.setDateFormat(int) is ignored #1529

@Marcono1234

Description

@Marcono1234

As described in https://stackoverflow.com/questions/6873020/gson-date-format, calling Gson.setDateFormat(int) has no effect, the created Gson object will not use the date format.

It appears the reason for this is that the method only sets dateStyle, but timeStyle remains unchanged, i.e. if it has not been changed before, then it is still DateFormat.DEFAULT.

public GsonBuilder setDateFormat(int style) {
this.dateStyle = style;
this.datePattern = null;
return this;

However addTypeAdaptersForDate only uses the styles if timeStyle != DateFormat.DEFAULT.

} else if (dateStyle != DateFormat.DEFAULT && timeStyle != DateFormat.DEFAULT) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions