Shahid Khan
Shahid Khan

Reputation: 33

JSON provider jackson issues with serializing and deserializing with Boolean type

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?

Upvotes: 3

Views: 8146

Answers (2)

StaxMan
StaxMan

Reputation: 116472

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.

Upvotes: 2

Hussain Pithawala
Hussain Pithawala

Reputation: 469

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/

Upvotes: 3

Related Questions