New (for 2.12) system, `CoercionConfigs`, updating deserializer impls

16 views
Skip to first unread message

Tatu Saloranta

unread,
Jun 8, 2020, 4:21:13 PM6/8/20
to jacks...@googlegroups.com, jackson-user
Hiya. One of big new features for 2.12 is new "Coercion Configs",
which is loosely modeled after existing "Config Overrides" system, but
separate (due to implementation challenges which made combined system
unworkable).
This work was completed under

https://github.com/FasterXML/jackson-databind/issues/2113

and usage can be seen f.ex on
`src/test/java/com/fasterxml/jackson/databind/deser/BeanCoercionTest.java`:

wherein you can configure ObjectMapper at 3 different level (global
defaults, logical type, concrete type:

----
mapper.coercionConfigFor(LogicalType.Integer).setCoercion(CoercionInputShape.String,
CoercionAction.TryConvert;)
----

which would basically allow coercion from JSON String into various
integral number types (int, long, Integer, Long BigInteger etc) if it
contains valid number representation.

While the configuration system itself can also indicate intended
semantics: JsonDeserializer implementations will need to do actual
coercions (or error reporting). I have added methods in
`StdDeserializer` base type to simplify this task, and a few
deserializers use them (including ones in `NumberDeserializers`).

At this point changes only cover some of implicitly approved (for now)
coercions and more work is needed. To this end I also created this
placeholder issue

https://github.com/FasterXML/jackson-databind/issues/2750

and I am hoping developers, users can add cases they think should be
covered, based on their actual needs (ideally). PRs for tests are also
appreciated, as well as obviously changes to add support for using new
configuration.
I will add some entries myself to bootstrap discussion.

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages