Skip to content

Commit

Permalink
Sliced ByteBuffer's Array Offset not respected FasterXML#1662
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-christian-schulze committed Sep 24, 2018
1 parent da902fa commit 08f3a58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void serialize(ByteBuffer bbuf, JsonGenerator gen, SerializerProvider pro
{
// first, simple case when wrapping an array...
if (bbuf.hasArray()) {
gen.writeBinary(bbuf.array(), 0, bbuf.limit());
gen.writeBinary(bbuf.array(), bbuf.arrayOffset(), bbuf.limit());
return;
}
// the other case is more complicated however. Best to handle with InputStream wrapper.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ public void testByteBuffer() throws IOException
assertEquals(exp, MAPPER.writeValueAsString(bbuf2));
}

// [Issue#1662]: Sliced ByteBuffers
public void testSlicedByteBuffer() throws IOException
{
final byte[] INPUT_BYTES = new byte[] { 1, 2, 3, 4, 5 };
String exp = MAPPER.writeValueAsString(new byte[] { 3, 4, 5 });
ByteBuffer bbuf = ByteBuffer.wrap(INPUT_BYTES);

bbuf.position(2);
ByteBuffer slicedBuf = bbuf.slice();

assertEquals(exp, MAPPER.writeValueAsString(slicedBuf));
}

// Verify that efficient UUID codec won't mess things up:
public void testUUIDs() throws IOException
{
Expand Down

0 comments on commit 08f3a58

Please sign in to comment.