2

I am using FlexJson within my play framework application but at the point I am trying to deseralize the json string it throws a java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean:

    User user = new JSONDeserializer<User>()
        .use(null, User.class).deserialize(body);

Body is the json string passed into the controller using standard jquery/ajax and where User has the following boolean value declared:

    public Boolean isCurrentUser;

Any ideas as to what I am doing wrong?

Thanks

Pere Villega
  • 16,429
  • 5
  • 63
  • 100
Chahal
  • 109
  • 1
  • 10

1 Answers1

1

In Json, Boolean is a type. Your JSon is:

{"user_id":"18","isCurrentUser":"true","title":"mr","description":"description"} 

when it should be:

{"user_id":"18","isCurrentUser":true,"title":"mr","description":"description"} 

Note that true is not a String, but a boolean. The parser fails because it finds a String instead of the expected boolean type. Fix the JSon generation to add a boolean, not a String.

Pere Villega
  • 16,429
  • 5
  • 63
  • 100