Skip to content

Commit

Permalink
Fix #793
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 15, 2015
1 parent 7db1f44 commit a143c05
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Project: jackson-databind
how is was deserialized first time
#785: Add handlings for classes which are available in `Thread.currentThread().getContextClassLoader()`
(contributed by Charles A)
#793: `ObjectMapper.readTree()` does not work with defaultTyping enabled

2.4.6 (23-Apr-2015)

Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,12 @@ public boolean useForType(JavaType t)
}
// fall through
case OBJECT_AND_NON_CONCRETE:
return (t.getRawClass() == Object.class) || !t.isConcrete()
// [Issue#88] Should not apply to JSON tree models:
|| TreeNode.class.isAssignableFrom(t.getRawClass());
// return t.isJavaLangObject() ||
return (t.getRawClass() == Object.class)
|| (!t.isConcrete()
// [databind#88] Should not apply to JSON tree models:
&& !TreeNode.class.isAssignableFrom(t.getRawClass()));

case NON_FINAL:
while (t.isArrayType()) {
t = t.getContentType();
Expand All @@ -184,6 +187,7 @@ public boolean useForType(JavaType t)
return !t.isFinal() && !TreeNode.class.isAssignableFrom(t.getRawClass());
default:
//case JAVA_LANG_OBJECT:
// return t.isJavaLangObject();
return (t.getRawClass() == Object.class);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ public void testBinary() throws Exception
assertEquals("\"Aw==\"", n.toString());

assertEquals("AAMD", new BinaryNode(data).asText());

// 1.6:
assertNodeNumbersForNonNumeric(n);
}

Expand All @@ -101,10 +99,25 @@ public void testPOJO()

assertEquals(new POJONode(null), new POJONode(null));

// 1.6:
// default; non-numeric
assertNodeNumbersForNonNumeric(n);
// but if wrapping actual number, use it
assertNodeNumbers(new POJONode(Integer.valueOf(123)), 123, 123.0);
}

// [databind#793]
public void testArrayWithDefaultTyping() throws Exception
{
ObjectMapper mapper = new ObjectMapper()
.enableDefaultTyping();

JsonNode array = mapper.readTree("[ 1, 2 ]");
assertTrue(array.isArray());
assertEquals(2, array.size());

JsonNode obj = mapper.readTree("{ \"a\" : 2 }");
assertTrue(obj.isObject());
assertEquals(1, obj.size());
assertEquals(2, obj.path("a").asInt());
}
}

0 comments on commit a143c05

Please sign in to comment.