@@ -23,13 +23,6 @@ public class CoerceMiscScalarsTest extends BaseMapTest
23
23
{
24
24
private final ObjectMapper DEFAULT_MAPPER = sharedMapper ();
25
25
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
-
33
26
private final ObjectMapper MAPPER_EMPTY_TO_EMPTY ;
34
27
{
35
28
MAPPER_EMPTY_TO_EMPTY = newJsonMapper ();
@@ -51,6 +44,13 @@ public class CoerceMiscScalarsTest extends BaseMapTest
51
44
.setCoercion (CoercionInputShape .EmptyString , CoercionAction .AsNull );
52
45
}
53
46
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
+
54
54
private final String JSON_EMPTY = quote ("" );
55
55
56
56
/*
@@ -63,8 +63,6 @@ public void testScalarDefaultsFromEmpty() throws Exception
63
63
{
64
64
// mostly as null, with some exceptions
65
65
66
- _testScalarEmptyToNull (DEFAULT_MAPPER , UUID .class );
67
-
68
66
_testScalarEmptyToNull (DEFAULT_MAPPER , File .class );
69
67
_testScalarEmptyToNull (DEFAULT_MAPPER , URL .class );
70
68
@@ -93,8 +91,6 @@ public void testScalarDefaultsFromEmpty() throws Exception
93
91
94
92
public void testScalarEmptyToNull () throws Exception
95
93
{
96
- _testScalarEmptyToNull (MAPPER_EMPTY_TO_NULL , UUID .class );
97
-
98
94
_testScalarEmptyToNull (MAPPER_EMPTY_TO_NULL , File .class );
99
95
_testScalarEmptyToNull (MAPPER_EMPTY_TO_NULL , URL .class );
100
96
_testScalarEmptyToNull (MAPPER_EMPTY_TO_NULL , URI .class );
@@ -111,9 +107,6 @@ public void testScalarEmptyToNull() throws Exception
111
107
112
108
public void testScalarEmptyToEmpty () throws Exception
113
109
{
114
- _testScalarEmptyToEmpty (MAPPER_EMPTY_TO_EMPTY , UUID .class ,
115
- new UUID (0L , 0L ));
116
-
117
110
_testScalarEmptyToNull (MAPPER_EMPTY_TO_EMPTY , File .class );
118
111
_testScalarEmptyToNull (MAPPER_EMPTY_TO_EMPTY , URL .class );
119
112
@@ -137,8 +130,6 @@ public void testScalarEmptyToEmpty() throws Exception
137
130
public void testScalarEmptyToTryConvert () throws Exception
138
131
{
139
132
// Should be same as `AsNull` for most but not all
140
- _testScalarEmptyToNull (MAPPER_EMPTY_TO_TRY_CONVERT , UUID .class );
141
-
142
133
_testScalarEmptyToNull (MAPPER_EMPTY_TO_TRY_CONVERT , File .class );
143
134
_testScalarEmptyToNull (MAPPER_EMPTY_TO_TRY_CONVERT , URL .class );
144
135
@@ -167,8 +158,6 @@ public void testScalarEmptyToTryConvert() throws Exception
167
158
168
159
public void testScalarsFailFromEmpty () throws Exception
169
160
{
170
- _verifyScalarToFail (MAPPER_EMPTY_TO_FAIL , UUID .class );
171
-
172
161
_verifyScalarToFail (MAPPER_EMPTY_TO_FAIL , File .class );
173
162
_verifyScalarToFail (MAPPER_EMPTY_TO_FAIL , URL .class );
174
163
_verifyScalarToFail (MAPPER_EMPTY_TO_FAIL , URI .class );
@@ -185,13 +174,37 @@ public void testScalarsFailFromEmpty() throws Exception
185
174
186
175
/*
187
176
/********************************************************
188
- /* Test methods, special type(s)
177
+ /* Test methods, (more) special type(s)
189
178
/********************************************************
190
179
*/
191
180
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
+
192
205
// StringBuilder is its own special type, since it naturally maps
193
206
// from String values, hence separate testing
194
- public void testStringBuilderDeser () throws Exception
207
+ public void testStringBuilderCoercions () throws Exception
195
208
{
196
209
// should result in an "empty" StringBuilder for all valid settings
197
210
_checkEmptyStringBuilder (DEFAULT_MAPPER .readValue (JSON_EMPTY , StringBuilder .class ));
0 commit comments