Skip to content

Commit

Permalink
Backport #1662 fix for 2.9(.8)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 23, 2018
1 parent 30d0c07 commit 08dfdde
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Project: jackson-databind
=== Releases ===
------------------------------------------------------------------------

2.9.8 (not yet released)

#1662: `ByteBuffer` serialization is broken if offset is not 0
(reported by j-baker@github)

2.9.7 (19-Sep-2018)

#2060: `UnwrappingBeanPropertyWriter` incorrectly assumes the found serializer is
Expand Down
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 @@ -122,13 +122,12 @@ public void testClass() throws IOException
assertEquals(quote("void"), MAPPER.writeValueAsString(Void.TYPE));
}

// [JACKSON-789]
public void testCharset() throws IOException
{
assertEquals(quote("UTF-8"), MAPPER.writeValueAsString(Charset.forName("UTF-8")));
}

// [Issue#239]: Support serialization of ByteBuffer
// [databind#239]: Support serialization of ByteBuffer
public void testByteBuffer() throws IOException
{
final byte[] INPUT_BYTES = new byte[] { 1, 2, 3, 4, 5 };
Expand All @@ -142,6 +141,19 @@ public void testByteBuffer() throws IOException
assertEquals(exp, MAPPER.writeValueAsString(bbuf2));
}

// [databind#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 08dfdde

Please sign in to comment.