@@ -89,43 +89,49 @@ private void _testEnumFromEmptyGlobalConfig(final CoercionInputShape shape, fina
89
89
ObjectMapper mapper ;
90
90
91
91
// First, coerce to null
92
- mapper = newJsonMapper ();
93
- mapper .coercionConfigDefaults ().setCoercion (shape , CoercionAction .AsNull )
94
- .setAcceptBlankAsEmpty (allowEmpty );
92
+ mapper = _globMapper (shape , CoercionAction .AsNull , allowEmpty );
95
93
assertNull (_verifyFromEmptyPass (mapper , json ));
96
94
97
95
// Then coerce as empty
98
- mapper = newJsonMapper ();
99
- mapper .coercionConfigDefaults ().setCoercion (shape , CoercionAction .AsEmpty )
100
- .setAcceptBlankAsEmpty (allowEmpty );
96
+ mapper = _globMapper (shape , CoercionAction .AsEmpty , allowEmpty );
101
97
EnumCoerce b = _verifyFromEmptyPass (mapper , json );
102
98
assertEquals (ENUM_DEFAULT , b );
103
99
104
100
// and finally, "try convert", which for Enums is same as "empty" (default)
105
- mapper = newJsonMapper ();
106
- mapper .coercionConfigDefaults ().setCoercion (shape , CoercionAction .TryConvert )
107
- .setAcceptBlankAsEmpty (allowEmpty );
101
+ mapper = _globMapper (shape , CoercionAction .TryConvert , allowEmpty );
108
102
assertEquals (ENUM_DEFAULT , _verifyFromEmptyPass (mapper , json ));
109
103
}
110
104
105
+ private ObjectMapper _globMapper (CoercionInputShape shape , CoercionAction act ,
106
+ Boolean allowEmpty )
107
+ {
108
+ ObjectMapper mapper = newJsonMapper ();
109
+ mapper .coercionConfigDefaults ().setCoercion (shape , act )
110
+ .setAcceptBlankAsEmpty (allowEmpty );
111
+ return mapper ;
112
+ }
113
+
111
114
private void _testEnumFromEmptyLogicalTypeConfig (final CoercionInputShape shape , final String json ,
112
115
Boolean allowEmpty )
113
116
throws Exception
114
117
{
115
118
ObjectMapper mapper ;
119
+ EnumCoerce b ;
116
120
117
121
// First, coerce to null
118
- mapper = newJsonMapper ();
119
- mapper .coercionConfigFor (LogicalType .Enum ).setCoercion (shape , CoercionAction .AsNull )
120
- .setAcceptBlankAsEmpty (allowEmpty );
121
- assertNull (_verifyFromEmptyPass (mapper , json ));
122
+ mapper = _logMapper (LogicalType .Enum , shape , CoercionAction .AsNull , allowEmpty );
123
+ b = _verifyFromEmptyPass (mapper , json );
124
+ assertNull (b );
122
125
123
126
// Then coerce as empty
124
- mapper = newJsonMapper ();
125
- mapper .coercionConfigFor (LogicalType .Enum ).setCoercion (shape , CoercionAction .AsEmpty )
126
- .setAcceptBlankAsEmpty (allowEmpty );
127
- EnumCoerce b = _verifyFromEmptyPass (mapper , json );
128
- assertNotNull (b );
127
+ mapper = _logMapper (LogicalType .Enum , shape , CoercionAction .AsEmpty , allowEmpty );
128
+ b = _verifyFromEmptyPass (mapper , json );
129
+ assertEquals (ENUM_DEFAULT , b );
130
+
131
+ // and with TryConvert (for enums same as empty)
132
+ mapper = _logMapper (LogicalType .Enum , shape , CoercionAction .TryConvert , allowEmpty );
133
+ b = _verifyFromEmptyPass (mapper , json );
134
+ assertEquals (ENUM_DEFAULT , b );
129
135
130
136
// But also make fail again with 2-level settings
131
137
mapper = newJsonMapper ();
@@ -136,24 +142,35 @@ private void _testEnumFromEmptyLogicalTypeConfig(final CoercionInputShape shape,
136
142
_verifyFromEmptyFail (mapper , json );
137
143
}
138
144
145
+ private ObjectMapper _logMapper (LogicalType type , CoercionInputShape shape , CoercionAction act ,
146
+ Boolean allowEmpty )
147
+ {
148
+ ObjectMapper mapper = newJsonMapper ();
149
+ mapper .coercionConfigFor (type ).setCoercion (shape , act )
150
+ .setAcceptBlankAsEmpty (allowEmpty );
151
+ return mapper ;
152
+ }
153
+
139
154
private void _testEnumFromEmptyPhysicalTypeConfig (final CoercionInputShape shape , final String json ,
140
155
Boolean allowEmpty )
141
156
throws Exception
142
157
{
143
158
ObjectMapper mapper ;
159
+ EnumCoerce b ;
144
160
145
161
// First, coerce to null
146
- mapper = newJsonMapper ();
147
- mapper .coercionConfigFor (EnumCoerce .class ).setCoercion (shape , CoercionAction .AsNull )
148
- .setAcceptBlankAsEmpty (allowEmpty );
149
- assertNull (_verifyFromEmptyPass (mapper , json ));
162
+ mapper = _physMapper (EnumCoerce .class , shape , CoercionAction .AsNull , allowEmpty );
163
+ b = _verifyFromEmptyPass (mapper , json );
164
+ assertNull (b );
150
165
151
166
// Then coerce as empty
152
- mapper = newJsonMapper ();
153
- mapper .coercionConfigFor (EnumCoerce .class ).setCoercion (shape , CoercionAction .AsEmpty )
154
- .setAcceptBlankAsEmpty (allowEmpty );
155
- EnumCoerce b = _verifyFromEmptyPass (mapper , json );
156
- assertNotNull (b );
167
+ mapper = _physMapper (EnumCoerce .class , shape , CoercionAction .AsEmpty , allowEmpty );
168
+ b = _verifyFromEmptyPass (mapper , json );
169
+ assertEquals (ENUM_DEFAULT , b );
170
+
171
+ mapper = _physMapper (EnumCoerce .class , shape , CoercionAction .TryConvert , allowEmpty );
172
+ b = _verifyFromEmptyPass (mapper , json );
173
+ assertEquals (ENUM_DEFAULT , b );
157
174
158
175
// But also make fail again with 2-level settings, with physical having precedence
159
176
mapper = newJsonMapper ();
@@ -163,6 +180,15 @@ private void _testEnumFromEmptyPhysicalTypeConfig(final CoercionInputShape shape
163
180
_verifyFromEmptyFail (mapper , json );
164
181
}
165
182
183
+ private ObjectMapper _physMapper (Class <?> type , CoercionInputShape shape , CoercionAction act ,
184
+ Boolean allowEmpty )
185
+ {
186
+ ObjectMapper mapper = newJsonMapper ();
187
+ mapper .coercionConfigFor (type ).setCoercion (shape , act )
188
+ .setAcceptBlankAsEmpty (allowEmpty );
189
+ return mapper ;
190
+ }
191
+
166
192
/*
167
193
/********************************************************
168
194
/* Verification helper methods
0 commit comments