Skip to content

Commit

Permalink
Fix #166 for 2.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 13, 2013
1 parent bc95acb commit 2fcd4d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Fixes:
* [Issue#157]: NPE when registering module twice
* [Issue#162]: JsonNodeFactory: work around an old bug with BigDecimal and zero
(submitted by fge@github)
* [Issue#166]: Incorrect optimization for `ObjectMapper.convertValue(Class)`
(reported by eric t)

------------------------------------------------------------------------
=== History: ===
Expand Down
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 @@ -2442,11 +2442,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 @@ -2463,17 +2458,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 @@ -2488,6 +2472,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 2fcd4d2

Please sign in to comment.