Skip to content

Commit

Permalink
Add test for serializing an instant
Browse files Browse the repository at this point in the history
  • Loading branch information
trickl committed Sep 13, 2019
1 parent 01f3271 commit 2ee43ba
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.github.trickl.jackson.module.httpquery.annotations.HttpQuery;
import java.io.IOException;
import java.time.Instant;
import java.time.LocalDate;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -42,6 +43,18 @@ private static class JsonFormatQuery {
private LocalDate value;
}


@HttpQuery
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
private static class JsonFormatEncodedQuery {
@JsonProperty("param")
@JsonFormat(shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd'T'HH:mm:ssX", timezone = "UTC")
private Instant value;
}

@Test
public void testStringParamSerialization() throws JsonProcessingException {
assertEquals(
Expand All @@ -55,4 +68,18 @@ public void testStringParamDeserialization() throws IOException {
new JsonFormatQuery(LocalDate.parse("2013-01-31")),
objectMapper.readValue("\"?param=2013-01-31\"", JsonFormatQuery.class));
}

@Test
public void testFormatEncodedSerialization() throws JsonProcessingException {
assertEquals(
"?param=2013-01-31T12%3A00%3A15Z",
objectMapper.valueToTree(new JsonFormatEncodedQuery(Instant.parse("2013-01-31T12:00:15Z"))).textValue());
}

@Test
public void testFormatEncodedDeserialization() throws IOException {
assertEquals(
new JsonFormatEncodedQuery(Instant.parse("2013-01-31T12:00:15Z")),
objectMapper.readValue("\"?param=2013-01-31T12%3A00%3A15Z\"", JsonFormatEncodedQuery.class));
}
}

0 comments on commit 2ee43ba

Please sign in to comment.