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

Not all ISO 8601 offset formats are accepted #487

Open
j-be opened this issue Apr 26, 2021 · 3 comments · May be fixed by #648
Open

Not all ISO 8601 offset formats are accepted #487

j-be opened this issue Apr 26, 2021 · 3 comments · May be fixed by #648
Assignees
Labels
bug Something isn't working right

Comments

@j-be
Copy link

j-be commented Apr 26, 2021

Describe the bug

Yasson fails on offsets formatted as +hhmm and +hh, even though they are considered valid ISO 8601 zone offsets (see https://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators)

To Reproduce

JsonbBuilder.create().fromJson("\"2021-04-26T16:14:44.538+0000\"", Date.class);
JsonbBuilder.create().fromJson("\"2021-04-26T16:14:44.538+00\"", Date.class);

Expected behavior

Above works.

System information:

  • OS: Linux Mint 20
  • Java Version: AdoptOpenJDK (build 11.0.10+9)
  • Yasson Version: 2.0.2

Additional context

The above examples works fine using LocalDateTime.parse(isoDate, DateTimeFormatter.ISO_OFFSET_DATE_TIME).

I will push a small test project to reproduce the issue shortly. Will link it here as soon as it is ready.

EDIT: Minimal project to reproduce can be found https://github.com/j-be/yasson-487

@j-be j-be added the bug Something isn't working right label Apr 26, 2021
@Verdent Verdent self-assigned this May 24, 2021
@Verdent
Copy link
Member

Verdent commented May 25, 2021

Hi @j-be , Thank you for reaching out. Unfortunately this behavior is by the spec. It is described which formatter should be used for each type if there is no formatter specified. For Date it is DateTimeFormatter.ISO_DATE_TIME if there is any time information present. This can be found in 3.5.1 of the JSONB-API spec.

@j-be
Copy link
Author

j-be commented May 25, 2021

@Verdent Thanks for the feedback. I see. So following the spec the right thing to do would be to use java.time.OffsetDateTime, is that correct?

@j-be
Copy link
Author

j-be commented May 25, 2021

After looking through it again - could it be that I (unknowingly) stumbled over a bug in Java itself here?

LocalDateTime.parse("2021-04-26T16:14:44.538+0000", DateTimeFormatter.ISO_ZONED_DATE_TIME); doesn't work, even though all of the following work:

  • LocalDateTime.parse("2021-04-26T16:14:44.538+00:00", DateTimeFormatter.ISO_ZONED_DATE_TIME);
  • LocalDateTime.parse("2021-04-26T16:14:44.538+00", DateTimeFormatter.ISO_ZONED_DATE_TIME);
  • LocalDateTime.parse("2021-04-26T16:14:44.538Z", DateTimeFormatter.ISO_ZONED_DATE_TIME);

The same is true for ISO_OFFSET_DATE_TIME. All of the above should imho. be valid ISO 8601 zone offsets.

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.

2 participants