77
88import com .fasterxml .jackson .annotation .JsonFormat ;
99import com .fasterxml .jackson .annotation .JsonFormat .Feature ;
10+ import com .fasterxml .jackson .annotation .JsonFormat .Shape ;
1011import com .fasterxml .jackson .core .JsonParser ;
1112import com .fasterxml .jackson .core .JsonToken ;
1213import com .fasterxml .jackson .databind .BeanProperty ;
@@ -39,10 +40,24 @@ public abstract class JSR310DateTimeDeserializerBase<T>
3940 */
4041 protected final boolean _isLenient ;
4142
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+
4256 protected JSR310DateTimeDeserializerBase (Class <T > supportedType , DateTimeFormatter f ) {
4357 super (supportedType );
4458 _formatter = f ;
4559 _isLenient = true ;
60+ _shape = null ;
4661 }
4762
4863 /**
@@ -53,6 +68,7 @@ protected JSR310DateTimeDeserializerBase(JSR310DateTimeDeserializerBase<T> base,
5368 super (base );
5469 _formatter = f ;
5570 _isLenient = base ._isLenient ;
71+ _shape = base ._shape ;
5672 }
5773
5874 /**
@@ -63,15 +79,34 @@ protected JSR310DateTimeDeserializerBase(JSR310DateTimeDeserializerBase<T> base,
6379 super (base );
6480 _formatter = base ._formatter ;
6581 _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 ;
6694 }
6795
96+
6897 protected abstract JSR310DateTimeDeserializerBase <T > withDateFormat (DateTimeFormatter dtf );
6998
7099 /**
71100 * @since 2.10
72101 */
73102 protected abstract JSR310DateTimeDeserializerBase <T > withLeniency (Boolean leniency );
74103
104+ /**
105+ * @since 2.11
106+ */
107+ protected abstract JSR310DateTimeDeserializerBase <T > withShape (Shape shape );
108+
109+
75110 @ Override
76111 public JsonDeserializer <?> createContextual (DeserializationContext ctxt ,
77112 BeanProperty property ) throws JsonMappingException
@@ -107,6 +142,12 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
107142 deser = deser .withLeniency (leniency );
108143 }
109144 }
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+ }
110151 // any use for TimeZone?
111152 }
112153 return deser ;
0 commit comments