|
11 | 11 | import java.util.Date; |
12 | 12 | import java.util.TimeZone; |
13 | 13 |
|
14 | | -import com.fasterxml.jackson.databind.util.ISO8601DateFormat; |
15 | 14 | import org.joda.time.DateTime; |
16 | 15 | import org.joda.time.DateTimeZone; |
17 | 16 | import org.junit.Test; |
|
24 | 23 | import com.fasterxml.jackson.core.JsonProcessingException; |
25 | 24 | import com.fasterxml.jackson.databind.ObjectMapper; |
26 | 25 | import com.fasterxml.jackson.databind.SerializationFeature; |
| 26 | +import com.fasterxml.jackson.databind.util.StdDateFormat; |
27 | 27 | import com.fasterxml.jackson.datatype.joda.JodaModule; |
28 | | -import com.fasterxml.jackson.datatype.jsr310.JSR310Module; |
| 28 | +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; |
29 | 29 |
|
30 | 30 | public class JacksonDateUnitTest { |
31 | 31 |
|
@@ -54,10 +54,12 @@ public void whenSerializingDateToISO8601_thenSerializedToText() throws JsonProce |
54 | 54 |
|
55 | 55 | final ObjectMapper mapper = new ObjectMapper(); |
56 | 56 | mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); |
57 | | - mapper.setDateFormat(new ISO8601DateFormat()); |
| 57 | + |
| 58 | + // StdDateFormat is ISO8601 since jackson 2.9 |
| 59 | + mapper.setDateFormat(new StdDateFormat().withColonInTimeZone(true)); |
58 | 60 |
|
59 | 61 | final String result = mapper.writeValueAsString(event); |
60 | | - assertThat(result, containsString("1970-01-01T02:30:00Z")); |
| 62 | + assertThat(result, containsString("1970-01-01T02:30:00.000+00:00")); |
61 | 63 | } |
62 | 64 |
|
63 | 65 | @Test |
@@ -152,7 +154,7 @@ public void whenSerializingJava8Date_thenCorrect() throws JsonProcessingExceptio |
152 | 154 | final LocalDateTime date = LocalDateTime.of(2014, 12, 20, 2, 30); |
153 | 155 |
|
154 | 156 | final ObjectMapper mapper = new ObjectMapper(); |
155 | | - mapper.registerModule(new JSR310Module()); |
| 157 | + mapper.registerModule(new JavaTimeModule()); |
156 | 158 | mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); |
157 | 159 |
|
158 | 160 | final String result = mapper.writeValueAsString(date); |
|
0 commit comments