You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently upgraded my jackson version 2.8.7 to 2.9.4 and serialization of an iterator with multiple sub-types seems broken.
Code to recreate the issue:
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.Iterator;
public class JacksonErrorTest {
private static Iterator<Number> numbers;
private static final ObjectMapper MAPPER = new ObjectMapper();
public static void main(String[] args) throws Exception {
ArrayList<Number> numbersList = new ArrayList<>();
numbersList.add(1);
numbersList.add(1.0);
numbers = numbersList.iterator();
MAPPER.writeValueAsString(numbers);
}
}
The exception stack trace is:
Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: java.lang.Double cannot be cast to java.lang.Integer
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._wrapAsIOE(DefaultSerializerProvider.java:509)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:482)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3893)
at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3207)
at JacksonErrorTest.main(JacksonErrorTest.java:21)
Caused by: java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer
at com.fasterxml.jackson.databind.ser.std.NumberSerializers$IntegerSerializer.serialize(NumberSerializers.java:137)
at com.fasterxml.jackson.databind.ser.impl.IteratorSerializer._serializeDynamicContents(IteratorSerializer.java:120)
at com.fasterxml.jackson.databind.ser.impl.IteratorSerializer.serializeContents(IteratorSerializer.java:80)
at com.fasterxml.jackson.databind.ser.impl.IteratorSerializer.serialize(IteratorSerializer.java:67)
at com.fasterxml.jackson.databind.ser.impl.IteratorSerializer.serialize(IteratorSerializer.java:13)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
... 4 more
Hello,
I recently upgraded my jackson version 2.8.7 to 2.9.4 and serialization of an iterator with multiple sub-types seems broken.
Code to recreate the issue:
The exception stack trace is:
It looks like the error is on this line:
https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/ser/impl/IteratorSerializer.java#L109
serializers.serializerFor(cc);
should be
serializer = serializers.serializerFor(cc);
The text was updated successfully, but these errors were encountered: