Jackson JSON Converts Integers to Strings

I use the mapper of an object to map to an object with String variables. This works too well, because even integers and booleans from JSON are converted to strings. Example:

{"my_variable":123} class MyClass{ String my_variable; } 

I would like the mapper object to report an error in such a situation instead of converting 123 to a string for my_variable. Is it possible?

+6
source share
1 answer

There is currently no such configuration, but can you override the default deserializer using a custom (see quickxml wiki ) and make this exception?

If you want a more convenient way, you can submit a request for improvement Jira; for example, the new DeserializationConfig.Feature.COERCE_STRINGS_AS_NUMBERS (true by default), which can be disabled to prevent such coercion.

+5
source

Source: https://habr.com/ru/post/899523/


All Articles