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

Default Serialization of java.util.Date does not generate ISO-8601 conform string #653

Open
RobertK66 opened this issue Nov 6, 2024 · 1 comment
Labels
bug Something isn't working right

Comments

@RobertK66
Copy link

Describe the bug
Using out of box configuration. (jsonb-3.0 feature of Liberty server 24.0.0.9) for REST services delivering a JSON record gives the following string value for a java.util.Date field:

"2024-11-06T16:06:15.168Z[UTC]"

This string having a "[UTC]" postfix showing (a assumed) UTC/+0 ZoneID in textual form is not ISO-8601 conform. It does raise exceptions when you try to deserialize this with current up to date dotnet JSON deserializer.

To Reproduce
use java.util.Date fields in REST response content without any annotations or configuration of the jsonb implementation.

Expected behavior
The serialized string should be ISO-8601 conform:

"2024-11-06T16:06:15.168Z"

System information:

  • OS: windows, IBM-I
  • Java Version: 15
  • Yasson Version: 3.0.? - could not pin down the exact version used by Liberty Server 24.0.0.9

Additional context
The javadoc of the used DateTimeFormatter.ISO_DATE_TIME states that it is only 'ISO-Like'. As described there, you can avoid to generate the non ISO standard square brackets by using a "ZoneOffset" instead of a "zoneID".

This would be an easy fix by changing the line 28 of the class DateSerializer.java from:

private static final DateTimeFormatter DEFAULT_DATE_FORMATTER = DateTimeFormatter.ISO_DATE_TIME.withZone(UTC);

to:

private static final DateTimeFormatter DEFAULT_DATE_FORMATTER = DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneOffset.UTC);

This makes a difference here because the const UTC in the current code is referencing a ZoneID by:

static final ZoneId UTC = ZoneId.of("UTC");

@RobertK66 RobertK66 added the bug Something isn't working right label Nov 6, 2024
@RobertK66 RobertK66 changed the title Default Serialization of java.util.Date does not generate ISO-8601 confirm string Default Serialization of java.util.Date does not generate ISO-8601 conform string Nov 6, 2024
@greek1979
Copy link
Contributor

I've seen this issue before, too, and fully concur that a fix is needed...

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

No branches or pull requests

2 participants