|
| 1 | +package com.fasterxml.jackson.datatype.jsr310.failing; |
| 2 | + |
| 3 | +import java.time.OffsetDateTime; |
| 4 | +import java.time.ZoneId; |
| 5 | +import java.time.temporal.ChronoUnit; |
| 6 | + |
| 7 | +import org.junit.Test; |
| 8 | + |
| 9 | +import com.fasterxml.jackson.annotation.JsonFormat; |
| 10 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 11 | +import com.fasterxml.jackson.datatype.jsr310.ModuleTestBase; |
| 12 | + |
| 13 | +import static org.junit.Assert.assertEquals; |
| 14 | + |
| 15 | +public class OffsetDateTimeDeser279Test extends ModuleTestBase |
| 16 | +{ |
| 17 | + // For [modules-java8#279] |
| 18 | + static class Wrapper279 { |
| 19 | + OffsetDateTime date; |
| 20 | + |
| 21 | + public Wrapper279(OffsetDateTime d) { date = d; } |
| 22 | + protected Wrapper279() { } |
| 23 | + |
| 24 | + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'") |
| 25 | + public OffsetDateTime getDate() { |
| 26 | + return date; |
| 27 | + } |
| 28 | + public void setDate(OffsetDateTime date) { |
| 29 | + this.date = date; |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + private ObjectMapper MAPPER = newMapper(); |
| 34 | + |
| 35 | + // For [modules-java8#279] |
| 36 | + @Test |
| 37 | + public void testWrapperWithPattern279() throws Exception |
| 38 | + { |
| 39 | + final OffsetDateTime date = OffsetDateTime.now(ZoneId.of("UTC")) |
| 40 | + .truncatedTo(ChronoUnit.SECONDS); |
| 41 | + final Wrapper279 input = new Wrapper279(date); |
| 42 | + final String json = MAPPER.writeValueAsString(input); |
| 43 | + |
| 44 | + Wrapper279 result = MAPPER.readValue(json, Wrapper279.class); |
| 45 | + assertEquals(input.date, result.date); |
| 46 | + } |
| 47 | +} |
0 commit comments