Skip to content

Commit 6a3d88d

Browse files
committed
Minor tweak to consider Date/Time types as scalars wrt MapperFeature.ALLOW_COERCION_OF_SCALARS
1 parent b1237dc commit 6a3d88d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/main/java/com/fasterxml/jackson/databind/cfg/CoercionConfigs.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,14 @@ public CoercionAction findCoercion(DeserializationConfig config,
203203
CoercionAction.TryConvert : CoercionAction.Fail;
204204
}
205205

206-
final boolean classicScalar = (targetType == LogicalType.Float)
206+
// classic scalars are numbers, booleans; but date/time also considered
207+
// scalar for this particular purpose
208+
final boolean baseScalar = (targetType == LogicalType.Float)
207209
|| (targetType == LogicalType.Integer)
208-
|| (targetType == LogicalType.Boolean);
210+
|| (targetType == LogicalType.Boolean)
211+
|| (targetType == LogicalType.DateTime);
209212

210-
if (classicScalar) {
213+
if (baseScalar) {
211214
// Default for setting in 2.x is true
212215
if (!config.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS)) {
213216
return CoercionAction.Fail;
@@ -217,8 +220,7 @@ public CoercionAction findCoercion(DeserializationConfig config,
217220
if (inputShape == CoercionInputShape.EmptyString) {
218221
// Since coercion of scalar must be enabled (see check above), allow empty-string
219222
// coercions by default even without this setting
220-
if (classicScalar
221-
|| (targetType == LogicalType.DateTime)
223+
if (baseScalar
222224
// Default for setting is false
223225
|| config.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
224226
return CoercionAction.AsNull;

0 commit comments

Comments
 (0)