Created
September 17, 2015 09:26
-
-
Save jloisel/1d36c017f5b27617c27b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
import org.apache.commons.lang3.tuple.ImmutablePair; | |
import org.apache.commons.lang3.tuple.Pair; | |
import org.junit.Test; | |
import com.fasterxml.jackson.core.JsonProcessingException; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
public class JacksonStackoverflowTest { | |
private final ObjectMapper mapper = new ObjectMapper(); | |
@Test | |
public void shouldNotStackOverflow() throws JsonProcessingException { | |
List<Pair<String, Double>> list = new ArrayList<>(); | |
list.add(ImmutablePair.of("Hello World!", 123d)); | |
// Throws StackOverflow error | |
mapper.writeValueAsString(list); | |
} | |
} |
Is it possible to reproduce this without external dependencies (Commons-lang in this case)?
Difference between 2.5 and 2.6 sounds strange, as there should not be difference in type handling.
I tried to reproduce with hand-made ImmutablePair and i could not reproduce it yet. There is something with the abstract or interfaces implemented in commons-lang3 which messes up the serialization.
Were you able to run this junit on your side? Anyway, it works fine with 2.5.4.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following JUnit shows that Jackson 2.6.2 cannot serialize properly a List<Pair<String, Double>>.