aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTatu Saloranta <tatu.saloranta@iki.fi>2020-06-18 16:38:27 -0700
committerTatu Saloranta <tatu.saloranta@iki.fi>2020-06-18 16:38:27 -0700
commitd32c188e3057b2c89e2d47c8e34fd8b91d65dca5 (patch)
tree3be337ba1f52335df455d606e5297f2ffc88146d /src/test
parent6985fe446e2684d2a5d708ccefbc5f3804e60045 (diff)
downloadjackson-databind-d32c188e3057b2c89e2d47c8e34fd8b91d65dca5.tar.gz
Fixed #2770
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/fasterxml/jackson/databind/struct/ScalarCoercionTest.java14
-rw-r--r--src/test/java/com/fasterxml/jackson/failing/ObjectMapper2757Test.java53
2 files changed, 62 insertions, 5 deletions
diff --git a/src/test/java/com/fasterxml/jackson/databind/struct/ScalarCoercionTest.java b/src/test/java/com/fasterxml/jackson/databind/struct/ScalarCoercionTest.java
index a7a30249b..1166caea7 100644
--- a/src/test/java/com/fasterxml/jackson/databind/struct/ScalarCoercionTest.java
+++ b/src/test/java/com/fasterxml/jackson/databind/struct/ScalarCoercionTest.java
@@ -164,14 +164,19 @@ public class ScalarCoercionTest extends BaseMapTest
_verifyRootStringCoerceFail("123.0", BigDecimal.class);
}
+ // [databind#2635], [databind#2770]
public void testToBooleanCoercionFailBytes() throws Exception
{
final String beanDoc = aposToQuotes("{'value':1}");
_verifyBooleanCoerceFail("1", true, JsonToken.VALUE_NUMBER_INT, "1", Boolean.TYPE);
_verifyBooleanCoerceFail("1", true, JsonToken.VALUE_NUMBER_INT, "1", Boolean.class);
_verifyBooleanCoerceFail(beanDoc, true, JsonToken.VALUE_NUMBER_INT, "1", BooleanPOJO.class);
+
+ _verifyBooleanCoerceFail("1.25", true, JsonToken.VALUE_NUMBER_FLOAT, "1.25", Boolean.TYPE);
+ _verifyBooleanCoerceFail("1.25", true, JsonToken.VALUE_NUMBER_FLOAT, "1.25", Boolean.class);
}
+ // [databind#2635], [databind#2770]
public void testToBooleanCoercionFailChars() throws Exception
{
final String beanDoc = aposToQuotes("{'value':1}");
@@ -179,7 +184,7 @@ public class ScalarCoercionTest extends BaseMapTest
_verifyBooleanCoerceFail("1", false, JsonToken.VALUE_NUMBER_INT, "1", Boolean.class);
_verifyBooleanCoerceFail(beanDoc, false, JsonToken.VALUE_NUMBER_INT, "1", BooleanPOJO.class);
}
-
+
public void testMiscCoercionFail() throws Exception
{
// And then we have coercions from more esoteric types too
@@ -273,9 +278,8 @@ public class ScalarCoercionTest extends BaseMapTest
private void _verifyBooleanCoerceFailReason(MismatchedInputException e,
JsonToken tokenType, String tokenValue) throws IOException
{
- verifyException(e, "Cannot coerce ");
- verifyException(e, " for type `");
- verifyException(e, "enable `MapperFeature.ALLOW_COERCION_OF_SCALARS` to allow");
+ // 2 different possibilities here
+ verifyException(e, "Cannot coerce Number", "Cannot deserialize instance of `");
JsonParser p = (JsonParser) e.getProcessor();
@@ -286,7 +290,7 @@ public class ScalarCoercionTest extends BaseMapTest
if (!tokenValue.equals(text)) {
String textDesc = (text == null) ? "NULL" : quote(text);
fail("Token text ("+textDesc+") via parser of type "+p.getClass().getName()
- +" not as expected ("+quote(tokenValue)+")");
+ +" not as expected ("+quote(tokenValue)+"); exception message: '"+e.getMessage()+"'");
}
}
}
diff --git a/src/test/java/com/fasterxml/jackson/failing/ObjectMapper2757Test.java b/src/test/java/com/fasterxml/jackson/failing/ObjectMapper2757Test.java
new file mode 100644
index 000000000..96556ff3a
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/failing/ObjectMapper2757Test.java
@@ -0,0 +1,53 @@
+package com.fasterxml.jackson.failing;
+
+import java.util.AbstractMap;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import com.fasterxml.jackson.databind.*;
+
+public class ObjectMapper2757Test extends BaseMapTest
+{
+ interface MultiValueMap<K, V> extends Map<K, List<V>> { }
+ abstract static class MyMultiMap<K, V> extends AbstractMap<K, List<V>>
+ implements MultiValueMap<K, V> { }
+
+ static class MyMap extends MyMultiMap<String, String> {
+ public MyMap() { }
+
+ public void setValue(StringWrapper w) { }
+ public void setValue(IntWrapper w) { }
+
+ public long getValue() { return 0L; }
+
+ @Override
+ public Set<Entry<String, List<String>>> entrySet() {
+ return Collections.emptySet();
+ }
+ }
+
+ private final ObjectMapper MAPPER = newJsonMapper();
+
+ // [databind#2757]: should allow deserialization as Map despite conflicting setters
+ public void testCanDeserializeMap() throws Exception
+ {
+// final String json = MAPPER.writeValueAsString(new MyMap());
+// System.out.println("json: "+json);
+ // MyMap x = MAPPER.readValue(json, MyMap.class);
+ final AtomicReference<Throwable> ref = new AtomicReference<>();
+ final JavaType type = MAPPER.constructType(MyMap.class);
+
+ System.err.println("Type: "+type);
+
+ boolean can = MAPPER.canDeserialize(MAPPER.constructType(type),
+ ref);
+System.err.println(" Cause -> "+ref.get());
+ if (!can) {
+ ref.get().printStackTrace();
+ fail("canDeserialize() returned false; underlying failure: "+ref.get());
+ }
+ }
+}