Skip to content

Commit

Permalink
[1.0.0]
Browse files Browse the repository at this point in the history
YearSerializer fixed
  • Loading branch information
GoodforGod committed Oct 30, 2021
1 parent 942a175 commit 084b99f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public YearSerializer(DateTimeFormatter formatter) {

@Override
public JsonElement serialize(Year src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src.getValue());
return new JsonPrimitive(src.format(formatter));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ void serializationIsValid() {

final String json = adapter.toJson(user);
assertNotNull(json);
assertTrue(json.contains("\"value\":" + VALUE), json);
assertTrue(json.contains("\"value\":\"" + VALUE + "\""), json);
}

@Test
void deserializationIsValid() {
void deserializationFromIntIsValid() {
final String json = "{\"name\":\"Bob\",\"value\":" + VALUE + "}";

final User user = adapter.fromJson(json, User.class);
Expand All @@ -65,6 +65,16 @@ void deserializationIsValid() {
assertEquals(VALUE_TIME, user.getValue());
}

@Test
void deserializationFromStringIsValid() {
final String json = "{\"name\":\"Bob\",\"value\":\"" + VALUE + "\"}";

final User user = adapter.fromJson(json, User.class);
assertNotNull(user);
assertEquals("Bob", user.getName());
assertEquals(VALUE_TIME, user.getValue());
}

@Test
void deserializationFails() {
final String json = "{\"name\":\"Bob\",\"value\":\"NOT_TIME\"}";
Expand Down

0 comments on commit 084b99f

Please sign in to comment.