Skip to content

Commit

Permalink
Update release notes wrt, made small changes to fix for #2602
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 28, 2020
1 parent c6da520 commit edf82d1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1027,3 +1027,8 @@ Tobias Preuss (johnjohndoe@github)
* Reported #2599: NoClassDefFoundError at DeserializationContext.<init> on Android 4.1.2
and Jackson 2.10.0
(2.10.3)
Eduard Tudenhöfner (nastra@github)
* Reported #2602, contributed fix for: ByteBufferSerializer produces unexpected results with
a duplicated ByteBuffer and a position > 0
(2.10.3)
6 changes: 5 additions & 1 deletion release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ Project: jackson-databind

2.10.3 (not yet released)

#2599: NoClassDefFoundError at DeserializationContext.<init> on Android 4.1.2 and Jackson 2.10.0
#2599: NoClassDefFoundError at DeserializationContext.<init> on Android 4.1.2
and Jackson 2.10.0
(reported by Tobias P)
#2602: ByteBufferSerializer produces unexpected results with a duplicated ByteBuffer
and a position > 0
(reported by Eduard T)

2.10.2 (05-Jan-2020)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,9 @@ public class ByteBufferSerializer extends StdScalarSerializer<ByteBuffer>
public void serialize(ByteBuffer bbuf, JsonGenerator gen, SerializerProvider provider) throws IOException
{
// first, simple case when wrapping an array...
if (bbuf.hasArray())
{
if (bbuf.position() > 0)
{
gen.writeBinary(bbuf.array(), bbuf.position(), bbuf.limit() - bbuf.position());
}
else
{
gen.writeBinary(bbuf.array(), bbuf.arrayOffset(), bbuf.limit());
}
if (bbuf.hasArray()) {
final int pos = bbuf.position();
gen.writeBinary(bbuf.array(), bbuf.arrayOffset() + pos, bbuf.limit() - pos);
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 @@ -150,26 +150,36 @@ public void testByteBuffer() throws IOException
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));
assertEquals(MAPPER.writeValueAsString(new byte[] { 3, 4, 5 }),
MAPPER.writeValueAsString(slicedBuf));

// but how about offset within?
slicedBuf.position(1);
assertEquals(MAPPER.writeValueAsString(new byte[] { 4, 5 }),
MAPPER.writeValueAsString(slicedBuf));
}

// [databind#2602]: Need to consider position()
public void testDuplicatedByteBufferWithCustomPosition() throws IOException
{
final byte[] INPUT_BYTES = new byte[] { 1, 2, 3, 4, 5 };
String exp = MAPPER.writeValueAsString(new byte[] { 3, 4, 5 });

String exp = MAPPER.writeValueAsString(new byte[] { 3, 4, 5 });
ByteBuffer bbuf = ByteBuffer.wrap(INPUT_BYTES);

bbuf.position(2);
ByteBuffer duplicated = bbuf.duplicate();

assertEquals(exp, MAPPER.writeValueAsString(duplicated));

// also check differently constructed bytebuffer (noting that
// offset given is the _position_ to use, NOT array offset
exp = MAPPER.writeValueAsString(new byte[] { 2, 3, 4 });
bbuf = ByteBuffer.wrap(INPUT_BYTES, 1, 3);
assertEquals(exp, MAPPER.writeValueAsString(bbuf.duplicate()));
}

// Verify that efficient UUID codec won't mess things up:
Expand Down

0 comments on commit edf82d1

Please sign in to comment.