Skip to content

Instantly share code, notes, and snippets.

@jloisel
Created September 23, 2015 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jloisel/c75ed016fd6607508ad7 to your computer and use it in GitHub Desktop.
Save jloisel/c75ed016fd6607508ad7 to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
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<ImmutablePair<String, Double>> list = new ArrayList<>();
list.add(ImmutablePair.of("Hello World!", 123d));
mapper.writeValueAsString(list);
}
public static interface Ability<T> {
}
public static final class ImmutablePair<L, R> implements Map.Entry<L, R>, Ability<ImmutablePair<L, R>> {
private final L key;
private final R value;
public ImmutablePair(final L key, final R value) {
super();
this.key = key;
this.value = value;
}
@Override
public L getKey() {
return key;
}
@Override
public R getValue() {
return value;
}
@Override
public R setValue(final R value) {
throw new UnsupportedOperationException();
}
static <L, R> ImmutablePair<L, R> of(final L left, final R right) {
return new ImmutablePair<L, R>(left, right);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment