Skip to content

Commit

Permalink
Fixing #166
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 13, 2013
1 parent ab93e9d commit d224319
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2446,11 +2446,6 @@ public <T> T convertValue(Object fromValue, Class<T> 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));
}

Expand All @@ -2467,17 +2462,6 @@ public <T> 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);
}

Expand All @@ -2492,6 +2476,18 @@ public <T> 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])
*/
Expand Down

0 comments on commit d224319

Please sign in to comment.