From 9d748173f579a1ae6cdf1be8686707f39d2c3fee Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Sun, 13 Mar 2016 21:35:09 -0700 Subject: [PATCH] Add test for #1161 --- .../jackson/databind/seq/ReadValuesTest.java | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/fasterxml/jackson/databind/seq/ReadValuesTest.java b/src/test/java/com/fasterxml/jackson/databind/seq/ReadValuesTest.java index dfdc22f14a..86d86699c4 100644 --- a/src/test/java/com/fasterxml/jackson/databind/seq/ReadValuesTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/seq/ReadValuesTest.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.BaseMapTest; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.MappingIterator; import com.fasterxml.jackson.databind.ObjectMapper; @@ -23,6 +24,20 @@ public boolean equals(Object o) { @Override public int hashCode() { return a; } } + static class Data1161 { + enum Type { + A, B, C; + + @Override + public String toString() { + return name().toLowerCase(); + }; + }; + + public Type type; + public String value; + } + /* /********************************************************** /* Unit tests; root-level value sequences via Mapper @@ -261,15 +276,15 @@ public void testNonRootMapsWithObjectReader() throws Exception public void testNonRootArraysUsingParser() throws Exception { final String JSON = "[[1],[3]]"; - JsonParser jp = MAPPER.getFactory().createParser(JSON); - assertToken(JsonToken.START_ARRAY, jp.nextToken()); + JsonParser p = MAPPER.getFactory().createParser(JSON); + assertToken(JsonToken.START_ARRAY, p.nextToken()); // Important: as of 2.1, START_ARRAY can only be skipped if the // target type is NOT a Collection or array Java type. // So we have to explicitly skip it in this particular case. - assertToken(JsonToken.START_ARRAY, jp.nextToken()); + assertToken(JsonToken.START_ARRAY, p.nextToken()); - Iterator it = MAPPER.readValues(jp, int[].class); + Iterator it = MAPPER.readValues(p, int[].class); assertTrue(it.hasNext()); int[] array = it.next(); @@ -280,6 +295,21 @@ public void testNonRootArraysUsingParser() throws Exception assertEquals(1, array.length); assertEquals(3, array[0]); assertFalse(it.hasNext()); - jp.close(); + p.close(); + } + + public void testDeserProps1161() throws Exception + { + final String src = "[ { \"type\": \"a\", \"value\": \"1\" }, { \"type\": \"b\", \"value\": \"2\" }]"; + MappingIterator iterator = MAPPER + .reader() + .with(DeserializationFeature.READ_ENUMS_USING_TO_STRING) + .forType(Data1161.class) + .readValues(src); + assertTrue(iterator.hasNext()); + Data1161 item = iterator.nextValue(); + assertNotNull(item); + assertSame(Data1161.Type.A, item.type); + iterator.close(); } }