File tree 3 files changed +21
-13
lines changed
main/java/com/fasterxml/jackson/databind/node
test/java/com/fasterxml/jackson/databind/node
3 files changed +21
-13
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ Project: jackson-databind
10
10
of type `UnwrappingBeanSerializer `
11
11
(reported by Petar T )
12
12
#2082 : `FactoryBasedEnumDeserializer` should be cachable
13
+ #2096 : `TreeTraversingParser` does not take base64 variant into account
14
+ (reported by tangiel @github )
13
15
#2109 : Canonical string for reference type is built incorrectly
14
16
(reported by svarzee @github )
15
17
Original file line number Diff line number Diff line change @@ -357,19 +357,13 @@ public byte[] getBinaryValue(Base64Variant b64variant)
357
357
{
358
358
// Multiple possibilities...
359
359
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 );
372
365
}
366
+ return n .binaryValue ();
373
367
}
374
368
// otherwise return null to mark we have no binary content
375
369
return null ;
Original file line number Diff line number Diff line change @@ -175,10 +175,22 @@ public void testBase64Text() throws Exception
175
175
try {
176
176
data = n .getBinaryValue (variant );
177
177
} 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 ());
179
179
}
180
180
assertNotNull (data );
181
181
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 ();
182
194
}
183
195
}
184
196
}
You can’t perform that action at this time.
0 commit comments