Skip to content

Commit 0b66b20

Browse files
committed
Mark #2066 as fixed (plus yet moar testing)
1 parent 831537b commit 0b66b20

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Project: jackson-databind
1313
#1919: Abstract class included as part of known type ids for error message
1414
when using JsonSubTypes
1515
(reported by Incara@github)
16+
#2066: Distinguish null from empty string for UUID deserialization
17+
(requested by leonshaw@github)
1618
#2091: `ReferenceType` does not expose valid containedType
1719
(reported by Nate B)
1820
#2113: Add `CoercionConfig[s]` mechanism for configuring allowed coercions

src/test/java/com/fasterxml/jackson/databind/convert/CoerceMiscScalarsTest.java

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ public class CoerceMiscScalarsTest extends BaseMapTest
2323
{
2424
private final ObjectMapper DEFAULT_MAPPER = sharedMapper();
2525

26-
private final ObjectMapper MAPPER_EMPTY_TO_FAIL;
27-
{
28-
MAPPER_EMPTY_TO_FAIL = newJsonMapper();
29-
MAPPER_EMPTY_TO_FAIL.coercionConfigDefaults()
30-
.setCoercion(CoercionInputShape.EmptyString, CoercionAction.Fail);
31-
}
32-
3326
private final ObjectMapper MAPPER_EMPTY_TO_EMPTY;
3427
{
3528
MAPPER_EMPTY_TO_EMPTY = newJsonMapper();
@@ -51,6 +44,13 @@ public class CoerceMiscScalarsTest extends BaseMapTest
5144
.setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsNull);
5245
}
5346

47+
private final ObjectMapper MAPPER_EMPTY_TO_FAIL;
48+
{
49+
MAPPER_EMPTY_TO_FAIL = newJsonMapper();
50+
MAPPER_EMPTY_TO_FAIL.coercionConfigDefaults()
51+
.setCoercion(CoercionInputShape.EmptyString, CoercionAction.Fail);
52+
}
53+
5454
private final String JSON_EMPTY = quote("");
5555

5656
/*
@@ -63,8 +63,6 @@ public void testScalarDefaultsFromEmpty() throws Exception
6363
{
6464
// mostly as null, with some exceptions
6565

66-
_testScalarEmptyToNull(DEFAULT_MAPPER, UUID.class);
67-
6866
_testScalarEmptyToNull(DEFAULT_MAPPER, File.class);
6967
_testScalarEmptyToNull(DEFAULT_MAPPER, URL.class);
7068

@@ -93,8 +91,6 @@ public void testScalarDefaultsFromEmpty() throws Exception
9391

9492
public void testScalarEmptyToNull() throws Exception
9593
{
96-
_testScalarEmptyToNull(MAPPER_EMPTY_TO_NULL, UUID.class);
97-
9894
_testScalarEmptyToNull(MAPPER_EMPTY_TO_NULL, File.class);
9995
_testScalarEmptyToNull(MAPPER_EMPTY_TO_NULL, URL.class);
10096
_testScalarEmptyToNull(MAPPER_EMPTY_TO_NULL, URI.class);
@@ -111,9 +107,6 @@ public void testScalarEmptyToNull() throws Exception
111107

112108
public void testScalarEmptyToEmpty() throws Exception
113109
{
114-
_testScalarEmptyToEmpty(MAPPER_EMPTY_TO_EMPTY, UUID.class,
115-
new UUID(0L, 0L));
116-
117110
_testScalarEmptyToNull(MAPPER_EMPTY_TO_EMPTY, File.class);
118111
_testScalarEmptyToNull(MAPPER_EMPTY_TO_EMPTY, URL.class);
119112

@@ -137,8 +130,6 @@ public void testScalarEmptyToEmpty() throws Exception
137130
public void testScalarEmptyToTryConvert() throws Exception
138131
{
139132
// Should be same as `AsNull` for most but not all
140-
_testScalarEmptyToNull(MAPPER_EMPTY_TO_TRY_CONVERT, UUID.class);
141-
142133
_testScalarEmptyToNull(MAPPER_EMPTY_TO_TRY_CONVERT, File.class);
143134
_testScalarEmptyToNull(MAPPER_EMPTY_TO_TRY_CONVERT, URL.class);
144135

@@ -167,8 +158,6 @@ public void testScalarEmptyToTryConvert() throws Exception
167158

168159
public void testScalarsFailFromEmpty() throws Exception
169160
{
170-
_verifyScalarToFail(MAPPER_EMPTY_TO_FAIL, UUID.class);
171-
172161
_verifyScalarToFail(MAPPER_EMPTY_TO_FAIL, File.class);
173162
_verifyScalarToFail(MAPPER_EMPTY_TO_FAIL, URL.class);
174163
_verifyScalarToFail(MAPPER_EMPTY_TO_FAIL, URI.class);
@@ -185,13 +174,37 @@ public void testScalarsFailFromEmpty() throws Exception
185174

186175
/*
187176
/********************************************************
188-
/* Test methods, special type(s)
177+
/* Test methods, (more) special type(s)
189178
/********************************************************
190179
*/
191180

181+
// UUID is quite compatible, but not exactly due to historical reasons;
182+
// also uses custom subtype, so test separately
183+
184+
public void testUUIDCoercions() throws Exception
185+
{
186+
// Coerce to `null` both by default, "TryConvert" and explicit
187+
_testScalarEmptyToNull(DEFAULT_MAPPER, UUID.class);
188+
_testScalarEmptyToNull(MAPPER_EMPTY_TO_NULL, UUID.class);
189+
_testScalarEmptyToNull(MAPPER_EMPTY_TO_TRY_CONVERT, UUID.class);
190+
191+
// but allow separate "empty" value is specifically requeted
192+
_testScalarEmptyToEmpty(MAPPER_EMPTY_TO_EMPTY, UUID.class,
193+
new UUID(0L, 0L));
194+
195+
// allow forcing failure, too
196+
_verifyScalarToFail(MAPPER_EMPTY_TO_FAIL, UUID.class);
197+
198+
// and allow failure with specifically configured per-class override, too
199+
ObjectMapper failMapper = newJsonMapper();
200+
failMapper.coercionConfigFor(UUID.class)
201+
.setCoercion(CoercionInputShape.EmptyString, CoercionAction.Fail);
202+
_verifyScalarToFail(failMapper, UUID.class);
203+
}
204+
192205
// StringBuilder is its own special type, since it naturally maps
193206
// from String values, hence separate testing
194-
public void testStringBuilderDeser() throws Exception
207+
public void testStringBuilderCoercions() throws Exception
195208
{
196209
// should result in an "empty" StringBuilder for all valid settings
197210
_checkEmptyStringBuilder(DEFAULT_MAPPER.readValue(JSON_EMPTY, StringBuilder.class));

0 commit comments

Comments
 (0)