Skip to content

Commit 0d60ab4

Browse files
committed
Add one more unit test for readValues(), to ensure it's possible to read POJOs within root-level arrays
1 parent dfa1b44 commit 0d60ab4

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ protected StaticListSerializerBase(Class<?> cls) {
1919
super(cls, false);
2020
}
2121

22+
@Deprecated // since 2.5
2223
@Override
2324
public boolean isEmpty(T value) {
25+
return isEmpty(null, value);
26+
}
27+
28+
@Override
29+
public boolean isEmpty(SerializerProvider provider, T value) {
2430
return (value == null) || (value.size() == 0);
2531
}
2632

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,35 @@ public void testRootBeans() throws Exception
6060
assertEquals(3, set.iterator().next().a);
6161
}
6262

63+
public void testRootBeansInArray() throws Exception
64+
{
65+
final String JSON = "[{\"a\":6}, {\"a\":-7}]";
66+
67+
MappingIterator<Bean> it = MAPPER.reader(Bean.class).readValues(JSON);
68+
69+
assertNotNull(it.getCurrentLocation());
70+
assertTrue(it.hasNext());
71+
Bean b = it.next();
72+
assertEquals(6, b.a);
73+
assertTrue(it.hasNext());
74+
b = it.next();
75+
assertEquals(-7, b.a);
76+
assertFalse(it.hasNext());
77+
it.close();
78+
79+
// Also, test 'readAll()'
80+
it = MAPPER.reader(Bean.class).readValues(JSON);
81+
List<Bean> all = it.readAll();
82+
assertEquals(2, all.size());
83+
it.close();
84+
85+
it = MAPPER.reader(Bean.class).readValues("[{\"a\":4},{\"a\":4}]");
86+
Set<Bean> set = it.readAll(new HashSet<Bean>());
87+
assertEquals(HashSet.class, set.getClass());
88+
assertEquals(1, set.size());
89+
assertEquals(4, set.iterator().next().a);
90+
}
91+
6392
public void testRootMaps() throws Exception
6493
{
6594
final String JSON = "{\"a\":3}{\"a\":27} ";
@@ -120,7 +149,7 @@ public void testRootArraysWithParser() throws Exception
120149
assertEquals(3, array[0]);
121150
assertFalse(it.hasNext());
122151
}
123-
152+
124153
public void testHasNextWithEndArray() throws Exception {
125154
final String JSON = "[1,3]";
126155
JsonParser jp = MAPPER.getFactory().createParser(JSON);
@@ -140,7 +169,7 @@ public void testHasNextWithEndArray() throws Exception {
140169
assertFalse(it.hasNext());
141170
assertFalse(it.hasNext());
142171
}
143-
172+
144173
public void testHasNextWithEndArrayManagedParser() throws Exception {
145174
final String JSON = "[1,3]";
146175

@@ -154,7 +183,7 @@ public void testHasNextWithEndArrayManagedParser() throws Exception {
154183
assertFalse(it.hasNext());
155184
assertFalse(it.hasNext());
156185
}
157-
186+
158187
/*
159188
/**********************************************************
160189
/* Unit tests; non-root arrays

0 commit comments

Comments
 (0)