Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date in TIME_IN_MILLIS not serialized as number #535

Closed
maxencelaurent opened this issue Feb 1, 2022 · 3 comments · Fixed by #550
Closed

Date in TIME_IN_MILLIS not serialized as number #535

maxencelaurent opened this issue Feb 1, 2022 · 3 comments · Fixed by #550
Assignees
Labels
bug Something isn't working right

Comments

@maxencelaurent
Copy link
Contributor

Describe the bug
According to jsonb-api (JsonbDateFormat#TIME_IN_MILLIS), a date formatted with the TIME_IN_MILLIS formatter shall be serialized as a number. This is not the case. Such dates are serialized as strings.

Explicit conversion to string is made here:

return String.valueOf(toInstant(object).toEpochMilli());

Then, this string is escaped when writing the JSON object in JsonGenerator#write(String).

To Reproduce
Serialize an instance of:

public class Dummy {

    @JsonbDateFormat(value = JsonbDateFormat.TIME_IN_MILLIS)
    private OffsetDateTime date;

    public OffsetDateTime getDate(){ return date;}
    public void setDate(OffsetDateTime date){  this.date = date;}
}

The JSON will looks like

{ "date": "1638953417522" }

Expected behavior

JSON should looks like

{ "date": 1638953417522 }

System information:

  • OS: Linux
  • Java Version: 11
  • Yasson Version: 2.0.4

Additional context
Deserialization works fine, with both representation:

{ "date": 1638953417522 }

{ "date": "1638953417522" }
@maxencelaurent maxencelaurent added the bug Something isn't working right label Feb 1, 2022
@Verdent
Copy link
Member

Verdent commented Feb 3, 2022

Hi @maxencelaurent , thank you for reaching out. This really seems like a bug. Thank you for reporting this. I will take a look at it.

@Verdent Verdent self-assigned this Feb 3, 2022
@abimarank
Copy link

Hi @Verdent, Are you working on this issue? If not, I planned to provide the fix.

@Verdent
Copy link
Member

Verdent commented Feb 4, 2022

Hi @abimarank , I did not yet started. Feel free to do it :-) Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants