Skip to content

Instantly share code, notes, and snippets.

@jloisel
Created September 17, 2015 09:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jloisel/1d36c017f5b27617c27b to your computer and use it in GitHub Desktop.
Save jloisel/1d36c017f5b27617c27b to your computer and use it in GitHub Desktop.
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);
}
}
@jloisel
Copy link
Author

jloisel commented Sep 17, 2015

The following JUnit shows that Jackson 2.6.2 cannot serialize properly a List<Pair<String, Double>>.

@cowtowncoder
Copy link

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.

@jloisel
Copy link
Author

jloisel commented Sep 23, 2015

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