5
5
import com .fasterxml .jackson .core .*;
6
6
import com .fasterxml .jackson .core .type .TypeReference ;
7
7
import com .fasterxml .jackson .databind .BaseMapTest ;
8
+ import com .fasterxml .jackson .databind .DeserializationFeature ;
8
9
import com .fasterxml .jackson .databind .MappingIterator ;
9
10
import com .fasterxml .jackson .databind .ObjectMapper ;
10
11
@@ -23,6 +24,20 @@ public boolean equals(Object o) {
23
24
@ Override public int hashCode () { return a ; }
24
25
}
25
26
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
+
26
41
/*
27
42
/**********************************************************
28
43
/* Unit tests; root-level value sequences via Mapper
@@ -261,15 +276,15 @@ public void testNonRootMapsWithObjectReader() throws Exception
261
276
public void testNonRootArraysUsingParser () throws Exception
262
277
{
263
278
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 ());
266
281
267
282
// Important: as of 2.1, START_ARRAY can only be skipped if the
268
283
// target type is NOT a Collection or array Java type.
269
284
// 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 ());
271
286
272
- Iterator <int []> it = MAPPER .readValues (jp , int [].class );
287
+ Iterator <int []> it = MAPPER .readValues (p , int [].class );
273
288
274
289
assertTrue (it .hasNext ());
275
290
int [] array = it .next ();
@@ -280,6 +295,21 @@ public void testNonRootArraysUsingParser() throws Exception
280
295
assertEquals (1 , array .length );
281
296
assertEquals (3 , array [0 ]);
282
297
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 ();
284
314
}
285
315
}
0 commit comments