7
7
8
8
import com .fasterxml .jackson .annotation .JsonFormat ;
9
9
import com .fasterxml .jackson .annotation .JsonFormat .Feature ;
10
+ import com .fasterxml .jackson .annotation .JsonFormat .Shape ;
10
11
import com .fasterxml .jackson .core .JsonParser ;
11
12
import com .fasterxml .jackson .core .JsonToken ;
12
13
import com .fasterxml .jackson .databind .BeanProperty ;
@@ -39,10 +40,24 @@ public abstract class JSR310DateTimeDeserializerBase<T>
39
40
*/
40
41
protected final boolean _isLenient ;
41
42
43
+ /**
44
+ * Setting that indicates the {@Link JsonFormat.Shape} specified for this deserializer
45
+ * as a {@link JsonFormat.Shape} annotation on property or class, or due to per-type
46
+ * "config override", or from global settings:
47
+ * If Shape is NUMBER_INT, the input value is considered to be epoch days. If not a
48
+ * NUMBER_INT, and the deserializer was not specified with the leniency setting of true,
49
+ * then an exception will be thrown.
50
+ * @see [jackson-modules-java8#58] for more info
51
+ *
52
+ * @since 2.11
53
+ */
54
+ protected final Shape _shape ;
55
+
42
56
protected JSR310DateTimeDeserializerBase (Class <T > supportedType , DateTimeFormatter f ) {
43
57
super (supportedType );
44
58
_formatter = f ;
45
59
_isLenient = true ;
60
+ _shape = null ;
46
61
}
47
62
48
63
/**
@@ -53,6 +68,7 @@ protected JSR310DateTimeDeserializerBase(JSR310DateTimeDeserializerBase<T> base,
53
68
super (base );
54
69
_formatter = f ;
55
70
_isLenient = base ._isLenient ;
71
+ _shape = base ._shape ;
56
72
}
57
73
58
74
/**
@@ -63,15 +79,34 @@ protected JSR310DateTimeDeserializerBase(JSR310DateTimeDeserializerBase<T> base,
63
79
super (base );
64
80
_formatter = base ._formatter ;
65
81
_isLenient = !Boolean .FALSE .equals (leniency );
82
+ _shape = base ._shape ;
83
+ }
84
+
85
+ /**
86
+ * @since 2.11
87
+ */
88
+ protected JSR310DateTimeDeserializerBase (JSR310DateTimeDeserializerBase <T > base ,
89
+ Shape shape ) {
90
+ super (base );
91
+ _formatter = base ._formatter ;
92
+ _shape = shape ;
93
+ _isLenient = base ._isLenient ;
66
94
}
67
95
96
+
68
97
protected abstract JSR310DateTimeDeserializerBase <T > withDateFormat (DateTimeFormatter dtf );
69
98
70
99
/**
71
100
* @since 2.10
72
101
*/
73
102
protected abstract JSR310DateTimeDeserializerBase <T > withLeniency (Boolean leniency );
74
103
104
+ /**
105
+ * @since 2.11
106
+ */
107
+ protected abstract JSR310DateTimeDeserializerBase <T > withShape (Shape shape );
108
+
109
+
75
110
@ Override
76
111
public JsonDeserializer <?> createContextual (DeserializationContext ctxt ,
77
112
BeanProperty property ) throws JsonMappingException
@@ -107,6 +142,12 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
107
142
deser = deser .withLeniency (leniency );
108
143
}
109
144
}
145
+ //Issue #58: For LocalDate deserializers we need to configure the formatter with
146
+ //a shape picked up from JsonFormat annotation, to decide if the value is EpochSeconds
147
+ JsonFormat .Shape shape = format .getShape ();
148
+ if (shape != null && shape != _shape ) {
149
+ deser = deser .withShape (shape );
150
+ }
110
151
// any use for TimeZone?
111
152
}
112
153
return deser ;
0 commit comments