-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
My prod environment uses version 2.7.4. but I also tested that the bug occurs with the latest version from maven 2.9.7.
My test case include different serializer /deserializer. To ensure compatibility I have some fuzzy which created random data pass it to one serializer and the result to another deserializer. The output is expected to be the same as the original input. One test however which creates a random byte array fails sporadically with jackson.
Here is a minimal test case (the "short" JSON was specifically chosen because the original error message said some about '/'. after simplifying the data structure the error message changed)
To reproduce it easily the other Base64 decoder is from the JRE 8:
import java.util.Arrays;
import java.util.Base64;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
public class JSONEncodingTest {
private static final String SHORT_BASE64_ENCODED_STRING = "A/A=";
private static final String LONG_BASE64_ENCODED_STRING = //
"eyJ0b3BpYyI6InRlc3QvdG9waWMvZm9yL2V2ZW50cy90b3BpYzAwMDE5L0U1ZjgiLCJwcm9wZXJ0aWVzIjp7ImNvbS5xaXZpY29uLnNlcnZpY2VzLnJlbW90ZS5ldmVudC5zZXF1ZW5jZS5udW1iZXIiOjM2OCwiZXZlbnQudG9waWNzIjoidGVzdC90b3BpYy9mb3IvZXZlbnRzL3RvcGljMDAwMTkvRTVmOCIsInVuaWNvZGUuc3RyaW5nIjoiZ0JBNVBUZjlhZ2d5aEFHdF/DnFpWZ1U3VMOWSi1hUHpow5ZoWlZOUmRMZVNrMUIxejRoX3BNd21WZ05Qw6RaSEVlcnd5NE9CRUJFRGFFRcOEdFVVNHJHM3VUw5xTSjnigqwwaTR6VVB2UnFqdlBZw4TDljNqbsOfaEFqNjc0X3U0ccO2TFFIeEZZSSJ9fQ";
private static final String JSON_SHORT = "{ \"data\" : \"" + SHORT_BASE64_ENCODED_STRING + "\"}";
private static final String JSON_LONG = "{ \"data\" : \"" + LONG_BASE64_ENCODED_STRING + "\"}";
public static class DataWrapper {
public byte[] data;
}
public static void main(String[] args) throws Exception {
decode(SHORT_BASE64_ENCODED_STRING, JSON_SHORT);
decode(LONG_BASE64_ENCODED_STRING, JSON_LONG);
}
public static void decode(final String base64, final String json) throws Exception {
final byte[] bytes = Base64.getDecoder().decode(base64);
System.out.println(Arrays.toString(bytes));
final ObjectMapper mapper = new ObjectMapper();
final ObjectReader textReader = mapper.readerFor(DataWrapper.class);
final DataWrapper jsonResult = textReader.readValue(json);
System.out.println(Arrays.equals(bytes, jsonResult.data));
}
}
Expected out would be:
[3, -16]
true
[123, 34, 116, 111, 112, 105, 99, 34, 58, 34, 116, 101, 115, 116, 47, 116, 111, 112, 105, 99, 47, 102, 111, 114, 47, 101, 118, 101, 110, 116, 115, 47, 116, 111, 112, 105, 99, 48, 48, 48, 49, 57, 47, 69, 53, 102, 56, 34, 44, 34, 112, 114, 111, 112, 101, 114, 116, 105, 101, 115, 34, 58, 123, 34, 99, 111, 109, 46, 113, 105, 118, 105, 99, 111, 110, 46, 115, 101, 114, 118, 105, 99, 101, 115, 46, 114, 101, 109, 111, 116, 101, 46, 101, 118, 101, 110, 116, 46, 115, 101, 113, 117, 101, 110, 99, 101, 46, 110, 117, 109, 98, 101, 114, 34, 58, 51, 54, 56, 44, 34, 101, 118, 101, 110, 116, 46, 116, 111, 112, 105, 99, 115, 34, 58, 34, 116, 101, 115, 116, 47, 116, 111, 112, 105, 99, 47, 102, 111, 114, 47, 101, 118, 101, 110, 116, 115, 47, 116, 111, 112, 105, 99, 48, 48, 48, 49, 57, 47, 69, 53, 102, 56, 34, 44, 34, 117, 110, 105, 99, 111, 100, 101, 46, 115, 116, 114, 105, 110, 103, 34, 58, 34, 103, 66, 65, 53, 80, 84, 102, 57, 97, 103, 103, 121, 104, 65, 71, 116, 95, -61, -100, 90, 86, 103, 85, 55, 84, -61, -106, 74, 45, 97, 80, 122, 104, -61, -106, 104, 90, 86, 78, 82, 100, 76, 101, 83, 107, 49, 66, 49, 122, 52, 104, 95, 112, 77, 119, 109, 86, 103, 78, 80, -61, -92, 90, 72, 69, 101, 114, 119, 121, 52, 79, 66, 69, 66, 69, 68, 97, 69, 69, -61, -124, 116, 85, 85, 52, 114, 71, 51, 117, 84, -61, -100, 83, 74, 57, -30, -126, -84, 48, 105, 52, 122, 85, 80, 118, 82, 113, 106, 118, 80, 89, -61, -124, -61, -106, 51, 106, 110, -61, -97, 104, 65, 106, 54, 55, 52, 95, 117, 52, 113, -61, -74, 76, 81, 72, 120, 70, 89, 73, 34, 125, 125]
true
but is
[3, -16]
true
[123, 34, 116, 111, 112, 105, 99, 34, 58, 34, 116, 101, 115, 116, 47, 116, 111, 112, 105, 99, 47, 102, 111, 114, 47, 101, 118, 101, 110, 116, 115, 47, 116, 111, 112, 105, 99, 48, 48, 48, 49, 57, 47, 69, 53, 102, 56, 34, 44, 34, 112, 114, 111, 112, 101, 114, 116, 105, 101, 115, 34, 58, 123, 34, 99, 111, 109, 46, 113, 105, 118, 105, 99, 111, 110, 46, 115, 101, 114, 118, 105, 99, 101, 115, 46, 114, 101, 109, 111, 116, 101, 46, 101, 118, 101, 110, 116, 46, 115, 101, 113, 117, 101, 110, 99, 101, 46, 110, 117, 109, 98, 101, 114, 34, 58, 51, 54, 56, 44, 34, 101, 118, 101, 110, 116, 46, 116, 111, 112, 105, 99, 115, 34, 58, 34, 116, 101, 115, 116, 47, 116, 111, 112, 105, 99, 47, 102, 111, 114, 47, 101, 118, 101, 110, 116, 115, 47, 116, 111, 112, 105, 99, 48, 48, 48, 49, 57, 47, 69, 53, 102, 56, 34, 44, 34, 117, 110, 105, 99, 111, 100, 101, 46, 115, 116, 114, 105, 110, 103, 34, 58, 34, 103, 66, 65, 53, 80, 84, 102, 57, 97, 103, 103, 121, 104, 65, 71, 116, 95, -61, -100, 90, 86, 103, 85, 55, 84, -61, -106, 74, 45, 97, 80, 122, 104, -61, -106, 104, 90, 86, 78, 82, 100, 76, 101, 83, 107, 49, 66, 49, 122, 52, 104, 95, 112, 77, 119, 109, 86, 103, 78, 80, -61, -92, 90, 72, 69, 101, 114, 119, 121, 52, 79, 66, 69, 66, 69, 68, 97, 69, 69, -61, -124, 116, 85, 85, 52, 114, 71, 51, 117, 84, -61, -100, 83, 74, 57, -30, -126, -84, 48, 105, 52, 122, 85, 80, 118, 82, 113, 106, 118, 80, 89, -61, -124, -61, -106, 51, 106, 110, -61, -97, 104, 65, 106, 54, 55, 52, 95, 117, 52, 113, -61, -74, 76, 81, 72, 120, 70, 89, 73, 34, 125, 125]
Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Unexpected end-of-input: was expecting closing quote for a string value
at [Source: (String)"{ "data" : "eyJ0b3BpYyI6InRlc3QvdG9waWMvZm9yL2V2ZW50cy90b3BpYzAwMDE5L0U1ZjgiLCJwcm9wZXJ0aWVzIjp7ImNvbS5xaXZpY29uLnNlcnZpY2VzLnJlbW90ZS5ldmVudC5zZXF1ZW5jZS5udW1iZXIiOjM2OCwiZXZlbnQudG9waWNzIjoidGVzdC90b3BpYy9mb3IvZXZlbnRzL3RvcGljMDAwMTkvRTVmOCIsInVuaWNvZGUuc3RyaW5nIjoiZ0JBNVBUZjlhZ2d5aEFHdF/DnFpWZ1U3VMOWSi1hUHpow5ZoWlZOUmRMZVNrMUIxejRoX3BNd21WZ05Qw6RaSEVlcnd5NE9CRUJFRGFFRcOEdFVVNHJHM3VUw5xTSjnigqwwaTR6VVB2UnFqdlBZw4TDljNqbsOfaEFqNjc0X3U0ccO2TFFIeEZZSSJ9fQ"}"; line: 1, column: 12] (through reference chain: JSONEncodingTest$DataWrapper["data"])
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:394)
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:353)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.wrapAndThrow(BeanDeserializerBase.java:1711)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:290)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1611)
at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1219)
at JSONEncodingTest.decode(JSONEncodingTest.java:36)
at JSONEncodingTest.main(JSONEncodingTest.java:25)
Caused by: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: was expecting closing quote for a string value
at [Source: (String)"{ "data" : "eyJ0b3BpYyI6InRlc3QvdG9waWMvZm9yL2V2ZW50cy90b3BpYzAwMDE5L0U1ZjgiLCJwcm9wZXJ0aWVzIjp7ImNvbS5xaXZpY29uLnNlcnZpY2VzLnJlbW90ZS5ldmVudC5zZXF1ZW5jZS5udW1iZXIiOjM2OCwiZXZlbnQudG9waWNzIjoidGVzdC90b3BpYy9mb3IvZXZlbnRzL3RvcGljMDAwMTkvRTVmOCIsInVuaWNvZGUuc3RyaW5nIjoiZ0JBNVBUZjlhZ2d5aEFHdF/DnFpWZ1U3VMOWSi1hUHpow5ZoWlZOUmRMZVNrMUIxejRoX3BNd21WZ05Qw6RaSEVlcnd5NE9CRUJFRGFFRcOEdFVVNHJHM3VUw5xTSjnigqwwaTR6VVB2UnFqdlBZw4TDljNqbsOfaEFqNjc0X3U0ccO2TFFIeEZZSSJ9fQ"}"; line: 1, column: 921]
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportInvalidEOF(ParserMinimalBase.java:594)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._finishString2(ReaderBasedJsonParser.java:2031)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._finishString(ReaderBasedJsonParser.java:2018)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.getText(ReaderBasedJsonParser.java:278)
at com.fasterxml.jackson.databind.deser.std.PrimitiveArrayDeserializers$ByteDeser.deserialize(PrimitiveArrayDeserializers.java:484)
at com.fasterxml.jackson.databind.deser.std.PrimitiveArrayDeserializers$ByteDeser.deserialize(PrimitiveArrayDeserializers.java:446)
at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:136)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
... 5 more