1
1
package com .fasterxml .jackson .databind .seq ;
2
2
3
+ import java .io .*;
3
4
import java .util .*;
4
5
5
6
import com .fasterxml .jackson .core .*;
8
9
import com .fasterxml .jackson .databind .BaseMapTest ;
9
10
import com .fasterxml .jackson .databind .MappingIterator ;
10
11
import com .fasterxml .jackson .databind .ObjectMapper ;
12
+ import com .fasterxml .jackson .databind .ObjectReader ;
11
13
12
14
@ SuppressWarnings ("resource" )
13
15
public class ReadValuesTest extends BaseMapTest
@@ -30,14 +32,61 @@ public boolean equals(Object o) {
30
32
/**********************************************************
31
33
*/
32
34
35
+ private enum Source {
36
+ STRING ,
37
+ INPUT_STREAM ,
38
+ READER ,
39
+ BYTE_ARRAY ,
40
+ BYTE_ARRAY_OFFSET
41
+ ;
42
+ }
43
+
33
44
private final ObjectMapper MAPPER = new ObjectMapper ();
34
45
35
46
public void testRootBeans () throws Exception
36
47
{
37
- final String JSON = "{\" a\" :3}{\" a\" :27} " ;
48
+ for (Source src : Source .values ()) {
49
+ _testRootBeans (src );
50
+ }
51
+ }
38
52
39
- MappingIterator <Bean > it = MAPPER .readerFor (Bean .class ).readValues (JSON );
53
+ private <T > MappingIterator <T > _iterator (ObjectReader r ,
54
+ String json ,
55
+ Source srcType ) throws IOException
56
+ {
57
+ switch (srcType ) {
58
+ case BYTE_ARRAY :
59
+ return r .readValues (json .getBytes ("UTF-8" ));
60
+ case BYTE_ARRAY_OFFSET :
61
+ {
62
+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
63
+ out .write (0 );
64
+ out .write (0 );
65
+ out .write (0 );
66
+ out .write (json .getBytes ("UTF-8" ));
67
+ out .write (0 );
68
+ out .write (0 );
69
+ out .write (0 );
70
+ byte [] b = out .toByteArray ();
71
+ return r .readValues (b , 3 , b .length -6 );
72
+ }
73
+ case INPUT_STREAM :
74
+ return r .readValues (new ByteArrayInputStream (json .getBytes ("UTF-8" )));
75
+ case READER :
76
+ return r .readValues (new StringReader (json ));
77
+ case STRING :
78
+ default :
79
+ return r .readValues (json );
80
+ }
81
+ }
82
+
83
+ private void _testRootBeans (Source srcType ) throws Exception
84
+ {
85
+ final String JSON = "{\" a\" :3}{\" a\" :27} " ;
40
86
87
+ MappingIterator <Bean > it = _iterator (MAPPER .readerFor (Bean .class ),
88
+ JSON , srcType );
89
+ MAPPER .readerFor (Bean .class ).readValues (JSON );
41
90
assertNotNull (it .getCurrentLocation ());
42
91
assertTrue (it .hasNext ());
43
92
Bean b = it .next ();
0 commit comments