Skip to content

Commit d16b8b1

Browse files
committed
Add failing tests for #2783
1 parent 9472834 commit d16b8b1

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ public Object handleUnexpectedToken(JavaType targetType, JsonParser p)
11981198
* {@link JsonToken#VALUE_NUMBER_INT} or {@link JsonToken#VALUE_NUMBER_FLOAT}.
11991199
*
12001200
* @param targetType Type that was to be instantiated
1201-
* @param t Token encountered that does match expected
1201+
* @param t Token encountered that does not match expected
12021202
* @param p Parser that points to the JSON value to decode
12031203
*
12041204
* @return Object that should be constructed, if any; has to be of type <code>instClass</code>

src/test/java/com/fasterxml/jackson/databind/ObjectReaderTest.java

+52-9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ static class POJO {
2626
public Map<String, Object> name;
2727
}
2828

29+
/*
30+
/**********************************************************
31+
/* Test methods, simple read/write with defaults
32+
/**********************************************************
33+
*/
34+
2935
public void testSimpleViaParser() throws Exception
3036
{
3137
final String JSON = "[1]";
@@ -89,6 +95,22 @@ public void testReaderForMapOf() throws Exception
8995
assertEquals(Collections.singletonMap("key", ABC.B), value);
9096
}
9197

98+
public void testNodeHandling() throws Exception
99+
{
100+
JsonNodeFactory nodes = new JsonNodeFactory(true);
101+
ObjectReader r = MAPPER.reader().with(nodes);
102+
// but also no further changes if attempting again
103+
assertSame(r, r.with(nodes));
104+
assertTrue(r.createArrayNode().isArray());
105+
assertTrue(r.createObjectNode().isObject());
106+
}
107+
108+
/*
109+
/**********************************************************
110+
/* Test methods, some alternative JSON settings
111+
/**********************************************************
112+
*/
113+
92114
public void testParserFeaturesComments() throws Exception
93115
{
94116
final String JSON = "[ /* foo */ 7 ]";
@@ -140,15 +162,11 @@ public void testParserFeaturesCtrlChars() throws Exception
140162
assertEquals(1, result.size());
141163
}
142164

143-
public void testNodeHandling() throws Exception
144-
{
145-
JsonNodeFactory nodes = new JsonNodeFactory(true);
146-
ObjectReader r = MAPPER.reader().with(nodes);
147-
// but also no further changes if attempting again
148-
assertSame(r, r.with(nodes));
149-
assertTrue(r.createArrayNode().isArray());
150-
assertTrue(r.createObjectNode().isObject());
151-
}
165+
/*
166+
/**********************************************************
167+
/* Test methods, config setting verification
168+
/**********************************************************
169+
*/
152170

153171
public void testFeatureSettings() throws Exception
154172
{
@@ -268,6 +286,31 @@ public void testGetValueType() throws Exception
268286
assertEquals(MAPPER.constructType(String.class), r.getValueType());
269287
}
270288

289+
public void testParserConfigViaMapper() throws Exception
290+
{
291+
try (JsonParser p = MAPPER.reader()
292+
.with(StreamReadFeature.STRICT_DUPLICATE_DETECTION)
293+
.createParser("[ ]")) {
294+
assertTrue(p.isEnabled(StreamReadFeature.STRICT_DUPLICATE_DETECTION));
295+
}
296+
297+
try (JsonParser p = MAPPER.reader()
298+
.with(JsonReadFeature.ALLOW_JAVA_COMMENTS)
299+
.createParser("[ ]")) {
300+
assertTrue(p.isEnabled(JsonReadFeature.ALLOW_JAVA_COMMENTS.mappedFeature()));
301+
}
302+
}
303+
304+
public void testGeneratorConfigViaMapper() throws Exception
305+
{
306+
StringWriter sw = new StringWriter();
307+
try (JsonGenerator g = MAPPER.writer()
308+
.with(StreamWriteFeature.IGNORE_UNKNOWN)
309+
.createGenerator(sw)) {
310+
assertTrue(g.isEnabled(StreamWriteFeature.IGNORE_UNKNOWN));
311+
}
312+
}
313+
271314
/*
272315
/**********************************************************
273316
/* Test methods, JsonPointer

0 commit comments

Comments
 (0)