diff options
author | Tatu Saloranta <tatu.saloranta@iki.fi> | 2020-06-18 19:57:16 -0700 |
---|---|---|
committer | Tatu Saloranta <tatu.saloranta@iki.fi> | 2020-06-18 19:57:16 -0700 |
commit | 73222382419e3cb42d234e52e94963b16c200509 (patch) | |
tree | 2eed3afe2d067a52fb71ef448118bed0f4e47537 /src/test/java/com/fasterxml/jackson | |
parent | 943f073d6e279550c340ee9fc097dbb0337e7329 (diff) | |
parent | 67764a75e3689111b91f40be7507ec3de9e130a5 (diff) | |
download | jackson-databind-73222382419e3cb42d234e52e94963b16c200509.tar.gz |
Merge branch '2.11' into 2.12
Diffstat (limited to 'src/test/java/com/fasterxml/jackson')
-rw-r--r-- | src/test/java/com/fasterxml/jackson/databind/deser/jdk/JDKScalarsTest.java | 2 | ||||
-rw-r--r-- | src/test/java/com/fasterxml/jackson/failing/UnwrapSingleArrayMiscTest.java | 73 |
2 files changed, 74 insertions, 1 deletions
diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/jdk/JDKScalarsTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/jdk/JDKScalarsTest.java index b88acd3a0..dae57c6db 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/jdk/JDKScalarsTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/jdk/JDKScalarsTest.java @@ -120,7 +120,7 @@ public class JDKScalarsTest private final ObjectMapper MAPPER = newJsonMapper(); - final ObjectMapper MAPPER_NO_COERCION =jsonMapperBuilder() + private final ObjectMapper MAPPER_NO_COERCION = jsonMapperBuilder() .disable(MapperFeature.ALLOW_COERCION_OF_SCALARS) .build(); diff --git a/src/test/java/com/fasterxml/jackson/failing/UnwrapSingleArrayMiscTest.java b/src/test/java/com/fasterxml/jackson/failing/UnwrapSingleArrayMiscTest.java new file mode 100644 index 000000000..f00485e49 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/failing/UnwrapSingleArrayMiscTest.java @@ -0,0 +1,73 @@ +package com.fasterxml.jackson.failing; + +import java.util.Collections; +import java.util.EnumMap; +import java.util.Map; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.exc.MismatchedInputException; + +public class UnwrapSingleArrayMiscTest extends BaseMapTest +{ + private final ObjectMapper UNWRAPPING_MAPPER = jsonMapperBuilder() + .enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS) + .build(); + + /* + /********************************************************** + /* Tests methods, POJOs + /********************************************************** + */ + + public void testSimplePOJOUnwrapping() throws Exception + { + ObjectReader r = UNWRAPPING_MAPPER.readerFor(IntWrapper.class); + IntWrapper w = r.readValue(aposToQuotes("[{'i':42}]")); + assertEquals(42, w.i); + + try { + r.readValue(aposToQuotes("[{'i':42},{'i':16}]")); + fail("Did not throw exception while reading a value from a multi value array"); + } catch (MismatchedInputException e) { + verifyException(e, "more than one value"); + } + } + + /* + /********************************************************** + /* Tests methods, Maps + /********************************************************** + */ + + // [databind#2767]: should work for Maps, too + public void testSimpleMapUnwrapping() throws Exception + { + ObjectReader r = UNWRAPPING_MAPPER.readerFor(Map.class); + Map<String,Object> m = r.readValue(aposToQuotes("[{'stuff':42}]")); + assertEquals(Collections.<String,Object>singletonMap("stuff", Integer.valueOf(42)), m); + + try { + r.readValue(aposToQuotes("[{'i':42},{'i':16}]")); + fail("Did not throw exception while reading a value from a multi value array"); + } catch (MismatchedInputException e) { + verifyException(e, "more than one value"); + } + } + + public void testEnumMapUnwrapping() throws Exception + { + ObjectReader r = UNWRAPPING_MAPPER.readerFor(new TypeReference<EnumMap<ABC,Integer>>() { }); + EnumMap<ABC,Integer> m = r.readValue(aposToQuotes("[{'A':42}]")); + EnumMap<ABC,Integer> exp = new EnumMap<>(ABC.class); + exp.put(ABC.A, Integer.valueOf(42)); + assertEquals(exp, m); + + try { + r.readValue(aposToQuotes("[{'A':42},{'B':13}]")); + fail("Did not throw exception while reading a value from a multi value array"); + } catch (MismatchedInputException e) { + verifyException(e, "more than one value"); + } + } +} |