|
| 1 | +package com.fasterxml.jackson.dataformat.ion; |
| 2 | + |
| 3 | +import org.junit.Test; |
| 4 | + |
| 5 | +import com.amazon.ion.Timestamp; |
| 6 | +import com.fasterxml.jackson.annotation.JsonCreator; |
| 7 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 8 | + |
| 9 | +import com.fasterxml.jackson.databind.DeserializationFeature; |
| 10 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 11 | + |
| 12 | +import com.fasterxml.jackson.dataformat.ion.ionvalue.IonValueModule; |
| 13 | + |
| 14 | +import static org.junit.Assert.assertEquals; |
| 15 | +import static org.junit.Assert.assertNotNull; |
| 16 | + |
| 17 | +// For [dataformats-binary#251] |
| 18 | +public class IonTimestampDeser251Test |
| 19 | +{ |
| 20 | + static class MessageWithoutTimestamp { |
| 21 | + final String message; |
| 22 | + final Integer count; |
| 23 | + |
| 24 | + @JsonCreator |
| 25 | + public MessageWithoutTimestamp(@JsonProperty("message") String message, |
| 26 | + @JsonProperty("count") Integer count) { |
| 27 | + this.message = message; |
| 28 | + this.count = count; |
| 29 | + } |
| 30 | + |
| 31 | + public String getMessage() { |
| 32 | + return message; |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + static class MessageWithTimestamp { |
| 37 | + final String message; |
| 38 | + final Integer count; |
| 39 | + |
| 40 | + public Timestamp timestamp; |
| 41 | + |
| 42 | + @JsonCreator |
| 43 | + public MessageWithTimestamp(@JsonProperty("message") String message, |
| 44 | + @JsonProperty("count") Integer count) { |
| 45 | + this.message = message; |
| 46 | + this.count = count; |
| 47 | + } |
| 48 | + |
| 49 | + public String getMessage() { |
| 50 | + return message; |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + private final ObjectMapper ION_MAPPER = IonObjectMapper.builder() |
| 55 | + .addModule(new IonValueModule()) |
| 56 | + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) |
| 57 | + .build(); |
| 58 | + |
| 59 | + // [dataformats-binary#251] |
| 60 | + @Test |
| 61 | + public void testDeserWithIgnoredBufferedTimestamp() throws Exception { |
| 62 | + String ion = "{message: \"Hello, world\", timestamp:2021-03-10T01:49:30.242-00:00}"; |
| 63 | + MessageWithoutTimestamp message = ION_MAPPER.readValue(ion, |
| 64 | + MessageWithoutTimestamp.class); |
| 65 | + assertNotNull(message); |
| 66 | + assertEquals("Hello, world", message.message); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void testDeserWithBufferedTimestamp() throws Exception { |
| 71 | + String ion = "{message: \"Hello, world\", timestamp:2021-03-10T01:49:30.242-00:00}"; |
| 72 | + MessageWithTimestamp message = ION_MAPPER.readValue(ion, |
| 73 | + MessageWithTimestamp.class); |
| 74 | + assertNotNull(message); |
| 75 | + assertEquals("Hello, world", message.message); |
| 76 | + assertNotNull(message.timestamp); |
| 77 | + } |
| 78 | +} |
0 commit comments