From d22431987daeb35a269888a1ce170d977a834001 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Tue, 12 Feb 2013 19:58:00 -0800 Subject: [PATCH] Fixing #166 --- .../jackson/databind/ObjectMapper.java | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index 2a0c196a12..175f5db68a 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -2446,11 +2446,6 @@ public T convertValue(Object fromValue, Class toValueType) { // sanity check for null first: if (fromValue == null) return null; - // also, as per [Issue-11], consider case for simple cast - // ... one caveat; while everything is Object.class, let's not take shortcut - if (toValueType != Object.class && toValueType.isAssignableFrom(fromValue.getClass())) { - return (T) fromValue; - } return (T) _convert(fromValue, _typeFactory.constructType(toValueType)); } @@ -2467,17 +2462,6 @@ public T convertValue(Object fromValue, JavaType toValueType) { // sanity check for null first: if (fromValue == null) return null; - // also, as per [Issue-11], consider case for simple cast - /* But with caveats: one is that while everything is Object.class, we don't - * want to "optimize" that out; and the other is that we also do not want - * to lose conversions of generic types. - */ - Class targetType = toValueType.getRawClass(); - if (targetType != Object.class - && !toValueType.hasGenericTypes() - && targetType.isAssignableFrom(fromValue.getClass())) { - return (T) fromValue; - } return (T) _convert(fromValue, toValueType); } @@ -2492,6 +2476,18 @@ public T convertValue(Object fromValue, JavaType toValueType) protected Object _convert(Object fromValue, JavaType toValueType) throws IllegalArgumentException { + // also, as per [Issue-11], consider case for simple cast + /* But with caveats: one is that while everything is Object.class, we don't + * want to "optimize" that out; and the other is that we also do not want + * to lose conversions of generic types. + */ + Class targetType = toValueType.getRawClass(); + if (targetType != Object.class + && !toValueType.hasGenericTypes() + && targetType.isAssignableFrom(fromValue.getClass())) { + return fromValue; + } + /* Then use TokenBuffer, which is a JsonGenerator: * (see [JACKSON-175]) */