Jackson JSON converts integers into strings

大城市里の小女人 提交于 2021-02-07 06:02:33

问题


I am using the object mapper to map into an object that has String variables. This works a little too well, because even integers and booleans from the JSON are converted into Strings. Example:

{"my_variable":123}

class MyClass{
    String my_variable;
}

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


回答1:


There is currently no such configuration, but you can override default deserializer with a custom one (see fasterxml wiki) and make that throw an exception?

If you would like a more convenient way you can file a Jira enhancement request; for example, new DeserializationConfig.Feature.COERCE_STRINGS_AS_NUMBERS (default to true) that one could disable to prevent such coercion.



来源:https://stackoverflow.com/questions/7806316/jackson-json-converts-integers-into-strings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!