Skip to content

Commit bbd8190

Browse files
committed
Fix #1362
1 parent 1d930db commit bbd8190

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Project: jackson-databind
77
2.7.8 (not yet released)
88

99
#1359: Improve `JsonNode` deserializer to create `FloatNode` if parser supports
10+
#1362: ObjectReader.readValues()` ignores offset and length when reading an array
11+
(reported by wastevenson@github)
1012

1113
2.7.7 (27-Aug-2016)
1214

src/main/java/com/fasterxml/jackson/databind/ObjectReader.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,8 @@ public <T> MappingIterator<T> readValues(byte[] src, int offset, int length)
14381438
if (_dataFormatReaders != null) {
14391439
return _detectBindAndReadValues(_dataFormatReaders.findFormat(src, offset, length), false);
14401440
}
1441-
return _bindAndReadValues(_considerFilter(_parserFactory.createParser(src), true));
1441+
return _bindAndReadValues(_considerFilter(_parserFactory.createParser(src, offset, length),
1442+
true));
14421443
}
14431444

14441445
/**

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

+51-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fasterxml.jackson.databind.seq;
22

3+
import java.io.*;
34
import java.util.*;
45

56
import com.fasterxml.jackson.core.*;
@@ -8,6 +9,7 @@
89
import com.fasterxml.jackson.databind.BaseMapTest;
910
import com.fasterxml.jackson.databind.MappingIterator;
1011
import com.fasterxml.jackson.databind.ObjectMapper;
12+
import com.fasterxml.jackson.databind.ObjectReader;
1113

1214
@SuppressWarnings("resource")
1315
public class ReadValuesTest extends BaseMapTest
@@ -30,14 +32,61 @@ public boolean equals(Object o) {
3032
/**********************************************************
3133
*/
3234

35+
private enum Source {
36+
STRING,
37+
INPUT_STREAM,
38+
READER,
39+
BYTE_ARRAY,
40+
BYTE_ARRAY_OFFSET
41+
;
42+
}
43+
3344
private final ObjectMapper MAPPER = new ObjectMapper();
3445

3546
public void testRootBeans() throws Exception
3647
{
37-
final String JSON = "{\"a\":3}{\"a\":27} ";
48+
for (Source src : Source.values()) {
49+
_testRootBeans(src);
50+
}
51+
}
3852

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} ";
4086

87+
MappingIterator<Bean> it = _iterator(MAPPER.readerFor(Bean.class),
88+
JSON, srcType);
89+
MAPPER.readerFor(Bean.class).readValues(JSON);
4190
assertNotNull(it.getCurrentLocation());
4291
assertTrue(it.hasNext());
4392
Bean b = it.next();

0 commit comments

Comments
 (0)