diff --git a/release-notes/VERSION b/release-notes/VERSION index 1406f85938..5fa746b404 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -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) diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index 76e8d62529..643984b730 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -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(); @@ -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); } } diff --git a/src/test/java/com/fasterxml/jackson/databind/node/TestJsonNode.java b/src/test/java/com/fasterxml/jackson/databind/node/TestJsonNode.java index 812f37f4d9..8dc121fa43 100644 --- a/src/test/java/com/fasterxml/jackson/databind/node/TestJsonNode.java +++ b/src/test/java/com/fasterxml/jackson/databind/node/TestJsonNode.java @@ -85,8 +85,6 @@ public void testBinary() throws Exception assertEquals("\"Aw==\"", n.toString()); assertEquals("AAMD", new BinaryNode(data).asText()); - - // 1.6: assertNodeNumbersForNonNumeric(n); } @@ -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()); + } }