Skip to content

Commit a143c05

Browse files
committed
Fix #793
1 parent 7db1f44 commit a143c05

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

release-notes/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Project: jackson-databind
1010
how is was deserialized first time
1111
#785: Add handlings for classes which are available in `Thread.currentThread().getContextClassLoader()`
1212
(contributed by Charles A)
13+
#793: `ObjectMapper.readTree()` does not work with defaultTyping enabled
1314

1415
2.4.6 (23-Apr-2015)
1516

src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,12 @@ public boolean useForType(JavaType t)
173173
}
174174
// fall through
175175
case OBJECT_AND_NON_CONCRETE:
176-
return (t.getRawClass() == Object.class) || !t.isConcrete()
177-
// [Issue#88] Should not apply to JSON tree models:
178-
|| TreeNode.class.isAssignableFrom(t.getRawClass());
176+
// return t.isJavaLangObject() ||
177+
return (t.getRawClass() == Object.class)
178+
|| (!t.isConcrete()
179+
// [databind#88] Should not apply to JSON tree models:
180+
&& !TreeNode.class.isAssignableFrom(t.getRawClass()));
181+
179182
case NON_FINAL:
180183
while (t.isArrayType()) {
181184
t = t.getContentType();
@@ -184,6 +187,7 @@ public boolean useForType(JavaType t)
184187
return !t.isFinal() && !TreeNode.class.isAssignableFrom(t.getRawClass());
185188
default:
186189
//case JAVA_LANG_OBJECT:
190+
// return t.isJavaLangObject();
187191
return (t.getRawClass() == Object.class);
188192
}
189193
}

src/test/java/com/fasterxml/jackson/databind/node/TestJsonNode.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ public void testBinary() throws Exception
8585
assertEquals("\"Aw==\"", n.toString());
8686

8787
assertEquals("AAMD", new BinaryNode(data).asText());
88-
89-
// 1.6:
9088
assertNodeNumbersForNonNumeric(n);
9189
}
9290

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

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

104-
// 1.6:
105102
// default; non-numeric
106103
assertNodeNumbersForNonNumeric(n);
107104
// but if wrapping actual number, use it
108105
assertNodeNumbers(new POJONode(Integer.valueOf(123)), 123, 123.0);
109106
}
107+
108+
// [databind#793]
109+
public void testArrayWithDefaultTyping() throws Exception
110+
{
111+
ObjectMapper mapper = new ObjectMapper()
112+
.enableDefaultTyping();
113+
114+
JsonNode array = mapper.readTree("[ 1, 2 ]");
115+
assertTrue(array.isArray());
116+
assertEquals(2, array.size());
117+
118+
JsonNode obj = mapper.readTree("{ \"a\" : 2 }");
119+
assertTrue(obj.isObject());
120+
assertEquals(1, obj.size());
121+
assertEquals(2, obj.path("a").asInt());
122+
}
110123
}

0 commit comments

Comments
 (0)