@@ -101,53 +101,70 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
101
101
BeanProperty property ) throws JsonMappingException
102
102
{
103
103
JsonFormat .Value format = findFormatOverrides (ctxt , property , handledType ());
104
+ return (format == null ) ? this : _withFormatOverrides (ctxt , property , format );
105
+ }
106
+
107
+ /**
108
+ * @param ctxt Active deserialization context
109
+ * @param property (optional) Property on which this deserializer is used, or {@code null}
110
+ * for root value
111
+ * @param formatOverrides Format overrides to use (non-null)
112
+ *
113
+ * @return Either this deserializer as is, or newly constructed variant if created
114
+ * for different configuration
115
+ *
116
+ * @since 2.12.1
117
+ */
118
+ protected JSR310DateTimeDeserializerBase <?> _withFormatOverrides (DeserializationContext ctxt ,
119
+ BeanProperty property , JsonFormat .Value formatOverrides )
120
+ {
104
121
JSR310DateTimeDeserializerBase <?> deser = this ;
105
- if (format != null ) {
106
- // 17-Aug-2019, tatu: For 2.10 let's start considering leniency/strictness too
107
- if (format .hasLenient ()) {
108
- Boolean leniency = format .getLenient ();
109
- if (leniency != null ) {
110
- deser = deser .withLeniency (leniency );
111
- }
122
+
123
+ // 17-Aug-2019, tatu: For 2.10 let's start considering leniency/strictness too
124
+ if (formatOverrides .hasLenient ()) {
125
+ Boolean leniency = formatOverrides .getLenient ();
126
+ if (leniency != null ) {
127
+ deser = deser .withLeniency (leniency );
112
128
}
113
- if (format .hasPattern ()) {
114
- final String pattern = format .getPattern ();
115
- final Locale locale = format .hasLocale () ? format .getLocale () : ctxt .getLocale ();
116
- DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder ();
117
- if (acceptCaseInsensitiveValues (ctxt , format )) {
118
- builder .parseCaseInsensitive ();
119
- }
120
- builder .appendPattern (pattern );
121
- DateTimeFormatter df ;
122
- if (locale == null ) {
123
- df = builder .toFormatter ();
124
- } else {
125
- df = builder .toFormatter (locale );
126
- }
127
-
128
- // [#148]: allow strict parsing
129
- if (!deser .isLenient ()) {
130
- df = df .withResolverStyle (ResolverStyle .STRICT );
131
- }
132
-
133
- // [#69]: For instant serializers/deserializers we need to configure the formatter with
134
- //a time zone picked up from JsonFormat annotation, otherwise serialization might not work
135
- if (format .hasTimeZone ()) {
136
- df = df .withZone (format .getTimeZone ().toZoneId ());
137
- }
138
- deser = deser .withDateFormat (df );
129
+ }
130
+ if (formatOverrides .hasPattern ()) {
131
+ final String pattern = formatOverrides .getPattern ();
132
+ final Locale locale = formatOverrides .hasLocale () ? formatOverrides .getLocale () : ctxt .getLocale ();
133
+ DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder ();
134
+ if (acceptCaseInsensitiveValues (ctxt , formatOverrides )) {
135
+ builder .parseCaseInsensitive ();
139
136
}
140
- // [#58]: For LocalDate deserializers we need to configure the formatter with
141
- //a shape picked up from JsonFormat annotation, to decide if the value is EpochSeconds
142
- JsonFormat .Shape shape = format .getShape ();
143
- if (shape != null && shape != _shape ) {
144
- deser = deser .withShape (shape );
137
+ builder .appendPattern (pattern );
138
+ DateTimeFormatter df ;
139
+ if (locale == null ) {
140
+ df = builder .toFormatter ();
141
+ } else {
142
+ df = builder .toFormatter (locale );
145
143
}
146
- // any use for TimeZone?
144
+
145
+ // [#148]: allow strict parsing
146
+ if (!deser .isLenient ()) {
147
+ df = df .withResolverStyle (ResolverStyle .STRICT );
148
+ }
149
+
150
+ // [#69]: For instant serializers/deserializers we need to configure the formatter with
151
+ //a time zone picked up from JsonFormat annotation, otherwise serialization might not work
152
+ if (formatOverrides .hasTimeZone ()) {
153
+ df = df .withZone (formatOverrides .getTimeZone ().toZoneId ());
154
+ }
155
+ deser = deser .withDateFormat (df );
147
156
}
157
+ // [#58]: For LocalDate deserializers we need to configure the formatter with
158
+ //a shape picked up from JsonFormat annotation, to decide if the value is EpochSeconds
159
+ JsonFormat .Shape shape = formatOverrides .getShape ();
160
+ if (shape != null && shape != _shape ) {
161
+ deser = deser .withShape (shape );
162
+ }
163
+ // any use for TimeZone?
164
+
148
165
return deser ;
149
166
}
150
-
167
+
151
168
private boolean acceptCaseInsensitiveValues (DeserializationContext ctxt , JsonFormat .Value format )
152
169
{
153
170
Boolean enabled = format .getFeature ( Feature .ACCEPT_CASE_INSENSITIVE_VALUES );
0 commit comments