-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
One of recurring themes regarding handling of simple scalar values (like numbers, Enums) is that some users want strict handling (only accept values with exactly matching types; JSON boolean for Java boolean), whereas others prefer coercions that may accept "close enough" matches (for example, accepting number 0
to map as false
for Java boolean
property).
Right now configurability is both limited and global: main mechanism is MapperFeature.ALLOW_COERCION_OF_SCALARS
; and there are DeserializationFeature
s like FAIL_ON_NULL_FOR_PRIMITIVES
, FAIL_ON_NUMBERS_FOR_ENUMS
.
But we could and should make use of another existing configuration mechanism:
@JsonFormat
has property lenient
, which, if set to false
, could indicate strict handling.
This setting is actually already used for Date/Time values, but as format feature it is already accessible, and can be configured:
- For individual property
- For type (class)
thus allowing much more fine-grained setting.
We could and should start with:
- Booleans
- Numbers (int, long, double, float etc)
- Enums
Note, too, that since default for property is OptBoolean.DEFAULT
, we can even distinguish between "lenient" / "not lenient" / "default", to allow further coercions, and leaving current set as "default" choice.