Skip to content

Commit d98ae77

Browse files
committed
Fix #2096
1 parent fd522c5 commit d98ae77

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Project: jackson-databind
1010
of type `UnwrappingBeanSerializer`
1111
(reported by Petar T)
1212
#2082: `FactoryBasedEnumDeserializer` should be cachable
13+
#2096: `TreeTraversingParser` does not take base64 variant into account
14+
(reported by tangiel@github)
1315
#2109: Canonical string for reference type is built incorrectly
1416
(reported by svarzee@github)
1517

src/main/java/com/fasterxml/jackson/databind/node/TreeTraversingParser.java

+6-12
Original file line numberDiff line numberDiff line change
@@ -357,19 +357,13 @@ public byte[] getBinaryValue(Base64Variant b64variant)
357357
{
358358
// Multiple possibilities...
359359
JsonNode n = currentNode();
360-
if (n != null) { // binary node?
361-
byte[] data = n.binaryValue();
362-
// (or TextNode, which can also convert automatically!)
363-
if (data != null) {
364-
return data;
365-
}
366-
// Or maybe byte[] as POJO?
367-
if (n.isPojo()) {
368-
Object ob = ((POJONode) n).getPojo();
369-
if (ob instanceof byte[]) {
370-
return (byte[]) ob;
371-
}
360+
if (n != null) {
361+
// [databind#2096]: although `binaryValue()` works for real binary node
362+
// and embedded "POJO" node, coercion from TextNode may require variant, so:
363+
if (n instanceof TextNode) {
364+
return ((TextNode) n).getBinaryValue(b64variant);
372365
}
366+
return n.binaryValue();
373367
}
374368
// otherwise return null to mark we have no binary content
375369
return null;

src/test/java/com/fasterxml/jackson/databind/node/TestConversions.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,22 @@ public void testBase64Text() throws Exception
175175
try {
176176
data = n.getBinaryValue(variant);
177177
} catch (Exception e) {
178-
throw new IOException("Failed (variant "+variant+", data length "+len+"): "+e.getMessage());
178+
fail("Failed (variant "+variant+", data length "+len+"): "+e.getMessage());
179179
}
180180
assertNotNull(data);
181181
assertArrayEquals(data, input);
182+
183+
// 15-Aug-2018, tatu: [databind#2096] requires another test
184+
JsonParser p = new TreeTraversingParser(n);
185+
assertEquals(JsonToken.VALUE_STRING, p.nextToken());
186+
try {
187+
data = p.getBinaryValue(variant);
188+
} catch (Exception e) {
189+
fail("Failed (variant "+variant+", data length "+len+"): "+e.getMessage());
190+
}
191+
assertNotNull(data);
192+
assertArrayEquals(data, input);
193+
p.close();
182194
}
183195
}
184196
}

0 commit comments

Comments
 (0)