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

Possible fix for issue #514 #515

Open
wants to merge 1 commit into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public class JsonbDateFormatter {
.appendValue(MINUTE_OF_HOUR, 2)
.appendLiteral(':')
.appendValue(SECOND_OF_MINUTE, 2)
.appendLiteral('Z')
.appendOffset("+HH:MM", "+00:00")
.appendOffset("+HH:MM", "Z")
.toFormatter();

private final DateTimeFormatter dateTimeFormatter;
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/org/eclipse/yasson/defaultmapping/IJsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public void testStrictCalendar() {
calendar.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));

String jsonString = jsonb.toJson(new ScalarValueWrapper<>(calendar));
assertEquals("{\"value\":\"1970-01-01T00:00:00Z+01:00\"}", jsonString);
assertEquals("{\"value\":\"1970-01-01T00:00:00+01:00\"}", jsonString);

ScalarValueWrapper<Calendar> result = jsonb.fromJson("{\"value\":\"1970-01-01T00:00:00Z+01:00\"}", new TestTypeToken<ScalarValueWrapper<Calendar>>() {}.getType());
ScalarValueWrapper<Calendar> result = jsonb.fromJson("{\"value\":\"1970-01-01T00:00:00+01:00\"}", new TestTypeToken<ScalarValueWrapper<Calendar>>() {}.getType());

assertEquals(calendar.toInstant(), result.getValue().toInstant());
}
Expand All @@ -56,9 +56,9 @@ public void testStrictDate() {
calendar.clear(Calendar.MILLISECOND);

String jsonString = jsonb.toJson(new ScalarValueWrapper<>(calendar.getTime()));
assertTrue(jsonString.matches("\\{\"value\":\"1970-01-01T00:00:00Z\\+[0-9]{2}:[0-9]{2}\"}"));
assertTrue(jsonString.matches("\\{\"value\":\"1970-01-01T00:00:00Z\"}"));

ScalarValueWrapper<Date> result = jsonb.fromJson("{\"value\":\"1970-01-01T00:00:00Z+00:00\"}", new TestTypeToken<ScalarValueWrapper<Date>>(){}.getType());
ScalarValueWrapper<Date> result = jsonb.fromJson("{\"value\":\"1970-01-01T00:00:00Z\"}", new TestTypeToken<ScalarValueWrapper<Date>>(){}.getType());
assertEquals(0, result.getValue().compareTo(calendar.getTime()));

}
Expand All @@ -67,18 +67,18 @@ public void testStrictDate() {
public void testStrictInstant() {
Instant instant = LocalDateTime.of(2017, 3, 24, 12,0,0).toInstant(ZoneOffset.MIN);
final String json = jsonb.toJson(new ScalarValueWrapper<>(instant));
assertEquals("{\"value\":\"2017-03-25T06:00:00Z+00:00\"}", json);
ScalarValueWrapper<Instant> result = jsonb.fromJson("{\"value\":\"2017-03-25T06:00:00Z+00:00\"}", new TestTypeToken<ScalarValueWrapper<Instant>>() {}.getType());
assertEquals("{\"value\":\"2017-03-25T06:00:00Z\"}", json);
ScalarValueWrapper<Instant> result = jsonb.fromJson("{\"value\":\"2017-03-25T06:00:00Z\"}", new TestTypeToken<ScalarValueWrapper<Instant>>() {}.getType());
assertEquals(instant, result.getValue());
}

@Test
public void testLocalDate() {
final LocalDate localDate = LocalDate.of(1970, 1, 1);
final String json = jsonb.toJson(new ScalarValueWrapper<>(localDate));
assertEquals("{\"value\":\"1970-01-01T00:00:00Z+00:00\"}", json);
assertEquals("{\"value\":\"1970-01-01T00:00:00Z\"}", json);

ScalarValueWrapper<LocalDate> result = jsonb.fromJson("{\"value\":\"1970-01-01T00:00:00Z+00:00\"}", new TestTypeToken<ScalarValueWrapper<LocalDate>>() {
ScalarValueWrapper<LocalDate> result = jsonb.fromJson("{\"value\":\"1970-01-01T00:00:00Z\"}", new TestTypeToken<ScalarValueWrapper<LocalDate>>() {
}.getType());


Expand All @@ -90,9 +90,9 @@ public void testLocalDateTime() {
final LocalDateTime localDateTime = LocalDateTime.of(1970, 1, 1, 1, 1, 1);
final String json = jsonb.toJson(new ScalarValueWrapper<>(localDateTime));

assertEquals("{\"value\":\"1970-01-01T01:01:01Z+00:00\"}", json);
assertEquals("{\"value\":\"1970-01-01T01:01:01Z\"}", json);

ScalarValueWrapper<LocalDateTime> result = jsonb.fromJson("{\"value\":\"1970-01-01T01:01:01Z+00:00\"}", new TestTypeToken<ScalarValueWrapper<LocalDateTime>>() {
ScalarValueWrapper<LocalDateTime> result = jsonb.fromJson("{\"value\":\"1970-01-01T01:01:01Z\"}", new TestTypeToken<ScalarValueWrapper<LocalDateTime>>() {
}.getType());


Expand Down