Skip to content

Commit 817d8ec

Browse files
committed
Minor improvement to StdDelegatingDeserializer, to allow 'updateValue()' use for some cases (and overload for others for extension)
1 parent 5c2ce7a commit 817d8ec

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/std/StdDelegatingDeserializer.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ public Class<?> handledType() {
155155
*/
156156

157157
@Override
158-
public T deserialize(JsonParser jp, DeserializationContext ctxt)
159-
throws IOException, JsonProcessingException
158+
public T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
160159
{
161160
Object delegateValue = _delegateDeserializer.deserialize(jp, ctxt);
162161
if (delegateValue == null) {
@@ -167,8 +166,7 @@ public T deserialize(JsonParser jp, DeserializationContext ctxt)
167166

168167
@Override
169168
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt,
170-
TypeDeserializer typeDeserializer)
171-
throws IOException, JsonProcessingException
169+
TypeDeserializer typeDeserializer) throws IOException
172170
{
173171
/* 03-Oct-2012, tatu: This is actually unlikely to work ok... but for now,
174172
* let's give it a chance?
@@ -181,6 +179,35 @@ public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt,
181179
return convertValue(delegateValue);
182180
}
183181

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+
184211
/*
185212
/**********************************************************
186213
/* Overridable methods

0 commit comments

Comments
 (0)