Created
September 23, 2015 19:05
-
-
Save jloisel/c75ed016fd6607508ad7 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 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