eclipse-ee4j / yasson

Eclipse Yasson project
https://projects.eclipse.org/projects/ee4j.yasson
Other
201 stars 95 forks source link

Not all ISO 8601 offset formats are accepted #487

Open j-be opened 3 years ago

j-be commented 3 years ago

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:

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

Verdent commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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:

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