|
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;
|
@@ -34,29 +35,63 @@ public abstract class JSR310DateTimeDeserializerBase<T>
|
34 | 35 | */
|
35 | 36 | protected final boolean _isLenient;
|
36 | 37 |
|
| 38 | + /** |
| 39 | + * Setting that indicates the {@Link JsonFormat.Shape} specified for this deserializer |
| 40 | + * as a {@link JsonFormat.Shape} annotation on property or class, or due to per-type |
| 41 | + * "config override", or from global settings: |
| 42 | + * If Shape is NUMBER_INT, the input value is considered to be epoch days. If not a |
| 43 | + * NUMBER_INT, and the deserializer was not specified with the leniency setting of true, |
| 44 | + * then an exception will be thrown. |
| 45 | + * @see [jackson-modules-java8#58] for more info |
| 46 | + * |
| 47 | + * @since 2.11 |
| 48 | + */ |
| 49 | + protected final Shape _shape; |
| 50 | + |
37 | 51 | protected JSR310DateTimeDeserializerBase(Class<T> supportedType, DateTimeFormatter f) {
|
38 | 52 | super(supportedType);
|
39 | 53 | _formatter = f;
|
40 | 54 | _isLenient = true;
|
| 55 | + _shape = null; |
41 | 56 | }
|
42 | 57 |
|
43 | 58 | protected JSR310DateTimeDeserializerBase(JSR310DateTimeDeserializerBase<T> base,
|
44 | 59 | DateTimeFormatter f) {
|
45 | 60 | super(base);
|
46 | 61 | _formatter = f;
|
47 | 62 | _isLenient = base._isLenient;
|
| 63 | + _shape = base._shape; |
48 | 64 | }
|
49 | 65 |
|
50 | 66 | protected JSR310DateTimeDeserializerBase(JSR310DateTimeDeserializerBase<T> base,
|
51 | 67 | Boolean leniency) {
|
52 | 68 | super(base);
|
53 | 69 | _formatter = base._formatter;
|
54 | 70 | _isLenient = !Boolean.FALSE.equals(leniency);
|
| 71 | + _shape = base._shape; |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * @since 2.11 |
| 76 | + */ |
| 77 | + protected JSR310DateTimeDeserializerBase(JSR310DateTimeDeserializerBase<T> base, |
| 78 | + Shape shape) { |
| 79 | + super(base); |
| 80 | + _formatter = base._formatter; |
| 81 | + _shape = shape; |
| 82 | + _isLenient = base._isLenient; |
55 | 83 | }
|
56 | 84 |
|
| 85 | + |
57 | 86 | protected abstract JSR310DateTimeDeserializerBase<T> withDateFormat(DateTimeFormatter dtf);
|
58 | 87 | protected abstract JSR310DateTimeDeserializerBase<T> withLeniency(Boolean leniency);
|
59 | 88 |
|
| 89 | + /** |
| 90 | + * @since 2.11 |
| 91 | + */ |
| 92 | + protected abstract JSR310DateTimeDeserializerBase<T> withShape(Shape shape); |
| 93 | + |
| 94 | + |
60 | 95 | @Override
|
61 | 96 | public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
|
62 | 97 | BeanProperty property) throws JsonMappingException
|
@@ -92,6 +127,12 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
|
92 | 127 | deser = deser.withLeniency(leniency);
|
93 | 128 | }
|
94 | 129 | }
|
| 130 | + //Issue #58: For LocalDate deserializers we need to configure the formatter with |
| 131 | + //a shape picked up from JsonFormat annotation, to decide if the value is EpochSeconds |
| 132 | + JsonFormat.Shape shape = format.getShape(); |
| 133 | + if (shape != null && shape != _shape) { |
| 134 | + deser = deser.withShape(shape); |
| 135 | + } |
95 | 136 | // any use for TimeZone?
|
96 | 137 | }
|
97 | 138 | return deser;
|
|
0 commit comments