aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatu Saloranta <tatu.saloranta@iki.fi>2020-06-09 18:00:39 -0700
committerTatu Saloranta <tatu.saloranta@iki.fi>2020-06-09 18:00:39 -0700
commit0b66b20294095a8e2d8d9aabba9eb984e6c5dac1 (patch)
tree21e48199c032eb2e9c0958885dc234dc5ca88546
parent831537be2b2d58f4533a3762e5f9f7671d35e499 (diff)
downloadjackson-databind-0b66b20294095a8e2d8d9aabba9eb984e6c5dac1.tar.gz
Mark #2066 as fixed (plus yet moar testing)
-rw-r--r--release-notes/VERSION-2.x2
-rw-r--r--src/test/java/com/fasterxml/jackson/databind/convert/CoerceMiscScalarsTest.java53
2 files changed, 35 insertions, 20 deletions
diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x
index 7ba519c5f..d76b28b48 100644
--- a/release-notes/VERSION-2.x
+++ b/release-notes/VERSION-2.x
@@ -13,6 +13,8 @@ Project: jackson-databind
#1919: Abstract class included as part of known type ids for error message
when using JsonSubTypes
(reported by Incara@github)
+#2066: Distinguish null from empty string for UUID deserialization
+ (requested by leonshaw@github)
#2091: `ReferenceType` does not expose valid containedType
(reported by Nate B)
#2113: Add `CoercionConfig[s]` mechanism for configuring allowed coercions
diff --git a/src/test/java/com/fasterxml/jackson/databind/convert/CoerceMiscScalarsTest.java b/src/test/java/com/fasterxml/jackson/databind/convert/CoerceMiscScalarsTest.java
index 06b9f98df..7256a3b2a 100644
--- a/src/test/java/com/fasterxml/jackson/databind/convert/CoerceMiscScalarsTest.java
+++ b/src/test/java/com/fasterxml/jackson/databind/convert/CoerceMiscScalarsTest.java
@@ -23,13 +23,6 @@ public class CoerceMiscScalarsTest extends BaseMapTest
{
private final ObjectMapper DEFAULT_MAPPER = sharedMapper();
- private final ObjectMapper MAPPER_EMPTY_TO_FAIL;
- {
- MAPPER_EMPTY_TO_FAIL = newJsonMapper();
- MAPPER_EMPTY_TO_FAIL.coercionConfigDefaults()
- .setCoercion(CoercionInputShape.EmptyString, CoercionAction.Fail);
- }
-
private final ObjectMapper MAPPER_EMPTY_TO_EMPTY;
{
MAPPER_EMPTY_TO_EMPTY = newJsonMapper();
@@ -51,6 +44,13 @@ public class CoerceMiscScalarsTest extends BaseMapTest
.setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsNull);
}
+ private final ObjectMapper MAPPER_EMPTY_TO_FAIL;
+ {
+ MAPPER_EMPTY_TO_FAIL = newJsonMapper();
+ MAPPER_EMPTY_TO_FAIL.coercionConfigDefaults()
+ .setCoercion(CoercionInputShape.EmptyString, CoercionAction.Fail);
+ }
+
private final String JSON_EMPTY = quote("");
/*
@@ -63,8 +63,6 @@ public class CoerceMiscScalarsTest extends BaseMapTest
{
// mostly as null, with some exceptions
- _testScalarEmptyToNull(DEFAULT_MAPPER, UUID.class);
-
_testScalarEmptyToNull(DEFAULT_MAPPER, File.class);
_testScalarEmptyToNull(DEFAULT_MAPPER, URL.class);
@@ -93,8 +91,6 @@ public class CoerceMiscScalarsTest extends BaseMapTest
public void testScalarEmptyToNull() throws Exception
{
- _testScalarEmptyToNull(MAPPER_EMPTY_TO_NULL, UUID.class);
-
_testScalarEmptyToNull(MAPPER_EMPTY_TO_NULL, File.class);
_testScalarEmptyToNull(MAPPER_EMPTY_TO_NULL, URL.class);
_testScalarEmptyToNull(MAPPER_EMPTY_TO_NULL, URI.class);
@@ -111,9 +107,6 @@ public class CoerceMiscScalarsTest extends BaseMapTest
public void testScalarEmptyToEmpty() throws Exception
{
- _testScalarEmptyToEmpty(MAPPER_EMPTY_TO_EMPTY, UUID.class,
- new UUID(0L, 0L));
-
_testScalarEmptyToNull(MAPPER_EMPTY_TO_EMPTY, File.class);
_testScalarEmptyToNull(MAPPER_EMPTY_TO_EMPTY, URL.class);
@@ -137,8 +130,6 @@ public class CoerceMiscScalarsTest extends BaseMapTest
public void testScalarEmptyToTryConvert() throws Exception
{
// Should be same as `AsNull` for most but not all
- _testScalarEmptyToNull(MAPPER_EMPTY_TO_TRY_CONVERT, UUID.class);
-
_testScalarEmptyToNull(MAPPER_EMPTY_TO_TRY_CONVERT, File.class);
_testScalarEmptyToNull(MAPPER_EMPTY_TO_TRY_CONVERT, URL.class);
@@ -167,8 +158,6 @@ public class CoerceMiscScalarsTest extends BaseMapTest
public void testScalarsFailFromEmpty() throws Exception
{
- _verifyScalarToFail(MAPPER_EMPTY_TO_FAIL, UUID.class);
-
_verifyScalarToFail(MAPPER_EMPTY_TO_FAIL, File.class);
_verifyScalarToFail(MAPPER_EMPTY_TO_FAIL, URL.class);
_verifyScalarToFail(MAPPER_EMPTY_TO_FAIL, URI.class);
@@ -185,13 +174,37 @@ public class CoerceMiscScalarsTest extends BaseMapTest
/*
/********************************************************
- /* Test methods, special type(s)
+ /* Test methods, (more) special type(s)
/********************************************************
*/
+ // UUID is quite compatible, but not exactly due to historical reasons;
+ // also uses custom subtype, so test separately
+
+ public void testUUIDCoercions() throws Exception
+ {
+ // Coerce to `null` both by default, "TryConvert" and explicit
+ _testScalarEmptyToNull(DEFAULT_MAPPER, UUID.class);
+ _testScalarEmptyToNull(MAPPER_EMPTY_TO_NULL, UUID.class);
+ _testScalarEmptyToNull(MAPPER_EMPTY_TO_TRY_CONVERT, UUID.class);
+
+ // but allow separate "empty" value is specifically requeted
+ _testScalarEmptyToEmpty(MAPPER_EMPTY_TO_EMPTY, UUID.class,
+ new UUID(0L, 0L));
+
+ // allow forcing failure, too
+ _verifyScalarToFail(MAPPER_EMPTY_TO_FAIL, UUID.class);
+
+ // and allow failure with specifically configured per-class override, too
+ ObjectMapper failMapper = newJsonMapper();
+ failMapper.coercionConfigFor(UUID.class)
+ .setCoercion(CoercionInputShape.EmptyString, CoercionAction.Fail);
+ _verifyScalarToFail(failMapper, UUID.class);
+ }
+
// StringBuilder is its own special type, since it naturally maps
// from String values, hence separate testing
- public void testStringBuilderDeser() throws Exception
+ public void testStringBuilderCoercions() throws Exception
{
// should result in an "empty" StringBuilder for all valid settings
_checkEmptyStringBuilder(DEFAULT_MAPPER.readValue(JSON_EMPTY, StringBuilder.class));