Skip to content

Commit

Permalink
Fix #1362
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 2, 2016
1 parent 1d930db commit bbd8190
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project: jackson-databind
2.7.8 (not yet released)

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

2.7.7 (27-Aug-2016)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,8 @@ public <T> MappingIterator<T> readValues(byte[] src, int offset, int length)
if (_dataFormatReaders != null) {
return _detectBindAndReadValues(_dataFormatReaders.findFormat(src, offset, length), false);
}
return _bindAndReadValues(_considerFilter(_parserFactory.createParser(src), true));
return _bindAndReadValues(_considerFilter(_parserFactory.createParser(src, offset, length),
true));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fasterxml.jackson.databind.seq;

import java.io.*;
import java.util.*;

import com.fasterxml.jackson.core.*;
Expand All @@ -8,6 +9,7 @@
import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;

@SuppressWarnings("resource")
public class ReadValuesTest extends BaseMapTest
Expand All @@ -30,14 +32,61 @@ public boolean equals(Object o) {
/**********************************************************
*/

private enum Source {
STRING,
INPUT_STREAM,
READER,
BYTE_ARRAY,
BYTE_ARRAY_OFFSET
;
}

private final ObjectMapper MAPPER = new ObjectMapper();

public void testRootBeans() throws Exception
{
final String JSON = "{\"a\":3}{\"a\":27} ";
for (Source src : Source.values()) {
_testRootBeans(src);
}
}

MappingIterator<Bean> it = MAPPER.readerFor(Bean.class).readValues(JSON);
private <T> MappingIterator<T> _iterator(ObjectReader r,
String json,
Source srcType) throws IOException
{
switch (srcType) {
case BYTE_ARRAY:
return r.readValues(json.getBytes("UTF-8"));
case BYTE_ARRAY_OFFSET:
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(0);
out.write(0);
out.write(0);
out.write(json.getBytes("UTF-8"));
out.write(0);
out.write(0);
out.write(0);
byte[] b = out.toByteArray();
return r.readValues(b, 3, b.length-6);
}
case INPUT_STREAM:
return r.readValues(new ByteArrayInputStream(json.getBytes("UTF-8")));
case READER:
return r.readValues(new StringReader(json));
case STRING:
default:
return r.readValues(json);
}
}

private void _testRootBeans(Source srcType) throws Exception
{
final String JSON = "{\"a\":3}{\"a\":27} ";

MappingIterator<Bean> it = _iterator(MAPPER.readerFor(Bean.class),
JSON, srcType);
MAPPER.readerFor(Bean.class).readValues(JSON);
assertNotNull(it.getCurrentLocation());
assertTrue(it.hasNext());
Bean b = it.next();
Expand Down

0 comments on commit bbd8190

Please sign in to comment.