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:
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:
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");