@@ -155,8 +155,7 @@ public Class<?> handledType() {
155
155
*/
156
156
157
157
@ Override
158
- public T deserialize (JsonParser jp , DeserializationContext ctxt )
159
- throws IOException , JsonProcessingException
158
+ public T deserialize (JsonParser jp , DeserializationContext ctxt ) throws IOException
160
159
{
161
160
Object delegateValue = _delegateDeserializer .deserialize (jp , ctxt );
162
161
if (delegateValue == null ) {
@@ -167,8 +166,7 @@ public T deserialize(JsonParser jp, DeserializationContext ctxt)
167
166
168
167
@ Override
169
168
public Object deserializeWithType (JsonParser jp , DeserializationContext ctxt ,
170
- TypeDeserializer typeDeserializer )
171
- throws IOException , JsonProcessingException
169
+ TypeDeserializer typeDeserializer ) throws IOException
172
170
{
173
171
/* 03-Oct-2012, tatu: This is actually unlikely to work ok... but for now,
174
172
* let's give it a chance?
@@ -181,6 +179,35 @@ public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt,
181
179
return convertValue (delegateValue );
182
180
}
183
181
182
+ @ SuppressWarnings ("unchecked" )
183
+ @ Override
184
+ public T deserialize (JsonParser p , DeserializationContext ctxt , Object intoValue )
185
+ throws IOException
186
+ {
187
+ if (_delegateType .getRawClass ().isAssignableFrom (intoValue .getClass ())){
188
+ return (T ) _delegateDeserializer .deserialize (p , ctxt , intoValue );
189
+ }
190
+ return (T ) _handleIncompatibleUpdateValue (p , ctxt , intoValue );
191
+ }
192
+
193
+ /**
194
+ * Overridable handler method called when {@link #deserialize(JsonParser, DeserializationContext, Object)}
195
+ * has been called with a value that is not compatible with delegate value.
196
+ * Since no conversion are expected for such "updateValue" case, this is normally not
197
+ * an operation that can be permitted, and the default behavior is to throw exception.
198
+ * Sub-classes may choose to try alternative approach if they have more information on
199
+ * exact usage and constraints.
200
+ *
201
+ * @since 2.6
202
+ */
203
+ protected Object _handleIncompatibleUpdateValue (JsonParser p , DeserializationContext ctxt , Object intoValue )
204
+ throws IOException
205
+ {
206
+ throw new UnsupportedOperationException (String .format
207
+ ("Can not update object of type %s (using deserializer for type %s)"
208
+ +intoValue .getClass ().getName (), _delegateType ));
209
+ }
210
+
184
211
/*
185
212
/**********************************************************
186
213
/* Overridable methods
0 commit comments