JSON provider jackson issues with serializing and deserializing with Boolean type

你。 提交于 2019-12-10 20:39:18

问题


I have a problem using Boolean wrapper with JSON Object, when JSON object is created for Boolean values it contain string cotes for example "isUrgent" : "1" Now the issue is I have to wrap it manually in my code each time for each request/response

Can any body please provide me a permanent solution for above problem?


回答1:


The solution is to customize the deserializer for the boolean type. All you need to do is add extra deserializer which could handle the case of particular String values which you aim to deserialize as the booleans.

Following blog post explains it in detail.

http://hussainpithawala.wordpress.com/2011/05/11/overriding-default-serializationdeserialization-behaviour-of-jackson-json-serializer/




回答2:


For what it is worth, boolean type can be converted from alternative JSON tokens (not just native true or false); so that

  • null becomes false
  • empty String ("") becomes false
  • strings "true" and "false" are accepted as matching boolean values
  • integer 0 becomes false; other integers true

but in this case you have combination of things, which is not supported.



来源:https://stackoverflow.com/questions/5965867/json-provider-jackson-issues-with-serializing-and-deserializing-with-boolean-typ

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