Skip to content

Commit 9d74817

Browse files
committed
Add test for #1161
1 parent 7a3b0b1 commit 9d74817

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

src/test/java/com/fasterxml/jackson/databind/seq/ReadValuesTest.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.fasterxml.jackson.core.*;
66
import com.fasterxml.jackson.core.type.TypeReference;
77
import com.fasterxml.jackson.databind.BaseMapTest;
8+
import com.fasterxml.jackson.databind.DeserializationFeature;
89
import com.fasterxml.jackson.databind.MappingIterator;
910
import com.fasterxml.jackson.databind.ObjectMapper;
1011

@@ -23,6 +24,20 @@ public boolean equals(Object o) {
2324
@Override public int hashCode() { return a; }
2425
}
2526

27+
static class Data1161 {
28+
enum Type {
29+
A, B, C;
30+
31+
@Override
32+
public String toString() {
33+
return name().toLowerCase();
34+
};
35+
};
36+
37+
public Type type;
38+
public String value;
39+
}
40+
2641
/*
2742
/**********************************************************
2843
/* Unit tests; root-level value sequences via Mapper
@@ -261,15 +276,15 @@ public void testNonRootMapsWithObjectReader() throws Exception
261276
public void testNonRootArraysUsingParser() throws Exception
262277
{
263278
final String JSON = "[[1],[3]]";
264-
JsonParser jp = MAPPER.getFactory().createParser(JSON);
265-
assertToken(JsonToken.START_ARRAY, jp.nextToken());
279+
JsonParser p = MAPPER.getFactory().createParser(JSON);
280+
assertToken(JsonToken.START_ARRAY, p.nextToken());
266281

267282
// Important: as of 2.1, START_ARRAY can only be skipped if the
268283
// target type is NOT a Collection or array Java type.
269284
// So we have to explicitly skip it in this particular case.
270-
assertToken(JsonToken.START_ARRAY, jp.nextToken());
285+
assertToken(JsonToken.START_ARRAY, p.nextToken());
271286

272-
Iterator<int[]> it = MAPPER.readValues(jp, int[].class);
287+
Iterator<int[]> it = MAPPER.readValues(p, int[].class);
273288

274289
assertTrue(it.hasNext());
275290
int[] array = it.next();
@@ -280,6 +295,21 @@ public void testNonRootArraysUsingParser() throws Exception
280295
assertEquals(1, array.length);
281296
assertEquals(3, array[0]);
282297
assertFalse(it.hasNext());
283-
jp.close();
298+
p.close();
299+
}
300+
301+
public void testDeserProps1161() throws Exception
302+
{
303+
final String src = "[ { \"type\": \"a\", \"value\": \"1\" }, { \"type\": \"b\", \"value\": \"2\" }]";
304+
MappingIterator<Data1161> iterator = MAPPER
305+
.reader()
306+
.with(DeserializationFeature.READ_ENUMS_USING_TO_STRING)
307+
.forType(Data1161.class)
308+
.readValues(src);
309+
assertTrue(iterator.hasNext());
310+
Data1161 item = iterator.nextValue();
311+
assertNotNull(item);
312+
assertSame(Data1161.Type.A, item.type);
313+
iterator.close();
284314
}
285315
}

0 commit comments

Comments
 (0)