bobolounna / restfb

Automatically exported from code.google.com/p/restfb
0 stars 0 forks source link

Unable to map JSON to Java. Offending JSON is 'true'. #117

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When I "like" a message with:

    client.publish("/" + fbId + "/likes", JsonObject.class);

The following problem appears:

com.restfb.exception.FacebookJsonMappingException: Unable to map JSON to Java. 
Offending JSON is 'true'.
    at com.restfb.DefaultJsonMapper.toJavaObject(DefaultJsonMapper.java:294)

(sorry for not giving the full stacktrace, but I don't have it right now)

I guess facebook outputs just "true", which is not considered valid. Should it?

Original issue reported on code.google.com by bozhidar...@gmail.com on 22 Feb 2011 at 11:15

GoogleCodeExporter commented 8 years ago
Yes, FB just outputs "true".  Is that ridiculous?  Yeah, I think so.  This is 
one of the least ugly not-really-JSON responses that FB returns, believe it or 
not...there are some pretty gross workarounds in RestFB to handle these kinds 
of situations.

Anyway, can you give this a try and see if it works?  There should be a special 
case in DefaultJsonMapper that correctly handles the invalid "true" situation 
when you map it to a Boolean.

client.publish(fbId + "/likes", Boolean.class);

If it works for you, let me know and I'll close this ticket out.  Thanks.

Original comment by mark.a.a...@gmail.com on 23 Feb 2011 at 3:14

GoogleCodeExporter commented 8 years ago
I'm not exactly a JSON expert, but I don't think it's so wrong to return 
"true". If a dynamic language was the client, it would simply need to check if 
(result). But anyway, I tried with Boolean.class and it worked.

Original comment by bozhidar...@gmail.com on 23 Feb 2011 at 5:10

GoogleCodeExporter commented 8 years ago
It's wrong as in it's not JSON by definition, which must be an object or array. 
 I totally get that this makes things simpler if you're using JS etc. to access 
the API, but it is inconsistent.  "Some of our API methods will return JSON, 
some of them will return random non-JSON strings".

Regardless of all this pedantry, I'm glad your situation has been resolved.  
Closing this out...

Original comment by mark.a.a...@gmail.com on 23 Feb 2011 at 5:27