File tree 1 file changed +40
-0
lines changed
datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/failing
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .fasterxml .jackson .datatype .jsr310 .failing ;
2
+
3
+ import java .time .Duration ;
4
+
5
+ import org .junit .Test ;
6
+
7
+ import com .fasterxml .jackson .annotation .JsonFormat ;
8
+ import com .fasterxml .jackson .annotation .JsonProperty ;
9
+ import com .fasterxml .jackson .databind .*;
10
+
11
+ import com .fasterxml .jackson .datatype .jsr310 .ModuleTestBase ;
12
+
13
+ import static org .junit .Assert .assertEquals ;
14
+
15
+ public class DurationSer224Test extends ModuleTestBase
16
+ {
17
+ // [datetime#224]
18
+ static class MyDto224 {
19
+ @ JsonFormat (pattern = "MINUTES"
20
+ // Work-around from issue:
21
+ // , without = JsonFormat.Feature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS
22
+ )
23
+ @ JsonProperty ("mins" )
24
+ private final Duration duration ;
25
+
26
+ public MyDto224 (Duration d ) { duration = d ; }
27
+
28
+ public Duration getDuration () { return duration ; }
29
+ }
30
+
31
+ private final ObjectMapper MAPPER = newMapper ();
32
+
33
+ // [datetime#224]
34
+ @ Test
35
+ public void testDurationFormatOverride () throws Exception
36
+ {
37
+ final String json = MAPPER .writeValueAsString (new MyDto224 (Duration .ofHours (2 )));
38
+ assertEquals (a2q ("{'mins':120}" ), json );
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments