Skip to content

Commit

Permalink
Fix #2096
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 15, 2018
1 parent fd522c5 commit d98ae77
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Project: jackson-databind
of type `UnwrappingBeanSerializer`
(reported by Petar T)
#2082: `FactoryBasedEnumDeserializer` should be cachable
#2096: `TreeTraversingParser` does not take base64 variant into account
(reported by tangiel@github)
#2109: Canonical string for reference type is built incorrectly
(reported by svarzee@github)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,19 +357,13 @@ public byte[] getBinaryValue(Base64Variant b64variant)
{
// Multiple possibilities...
JsonNode n = currentNode();
if (n != null) { // binary node?
byte[] data = n.binaryValue();
// (or TextNode, which can also convert automatically!)
if (data != null) {
return data;
}
// Or maybe byte[] as POJO?
if (n.isPojo()) {
Object ob = ((POJONode) n).getPojo();
if (ob instanceof byte[]) {
return (byte[]) ob;
}
if (n != null) {
// [databind#2096]: although `binaryValue()` works for real binary node
// and embedded "POJO" node, coercion from TextNode may require variant, so:
if (n instanceof TextNode) {
return ((TextNode) n).getBinaryValue(b64variant);
}
return n.binaryValue();
}
// otherwise return null to mark we have no binary content
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,22 @@ public void testBase64Text() throws Exception
try {
data = n.getBinaryValue(variant);
} catch (Exception e) {
throw new IOException("Failed (variant "+variant+", data length "+len+"): "+e.getMessage());
fail("Failed (variant "+variant+", data length "+len+"): "+e.getMessage());
}
assertNotNull(data);
assertArrayEquals(data, input);

// 15-Aug-2018, tatu: [databind#2096] requires another test
JsonParser p = new TreeTraversingParser(n);
assertEquals(JsonToken.VALUE_STRING, p.nextToken());
try {
data = p.getBinaryValue(variant);
} catch (Exception e) {
fail("Failed (variant "+variant+", data length "+len+"): "+e.getMessage());
}
assertNotNull(data);
assertArrayEquals(data, input);
p.close();
}
}
}
Expand Down

0 comments on commit d98ae77

Please sign in to comment.