bobolounna / restfb

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

Special case JSON mapping for FB bug ("attachment":[] in response) #128

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Call executeQuery() by selecting attachment.fb_object_id from the stream 
table which returns results containing posts without attachments.
2. An exception is thrown with the message: JSON is an array but is being 
mapped as an object - you should map it as a List instead. Offending JSON is 
'[]'

What is the expected output? What do you see instead?
The JSONMapper should parse the results as a null attachment. Instead, it is 
throwing an error.

What version of the product are you using? On what operating system?
restFB 1.6.3

Please provide any additional information below.
I wrote up this Facebook bug to address the cause of the issue:
http://bugs.developers.facebook.net/show_bug.cgi?id=16179

This issue is very similar to Issue #76 
(http://code.google.com/p/restfb/issues/detail?id=76)

Original issue reported on code.google.com by blick...@gmail.com on 24 Mar 2011 at 5:25

GoogleCodeExporter commented 8 years ago
There is support in the JSON mapper to map the same FB field name to multiple 
Java types.  For example, you might try to map to a class like this:

public class QueryResult {
  @Facebook("attachment")
  private List<String> emptyAttachments = new ArrayList<String>();

  @Facebook("attachment")
  private QueryAttachment queryAttachment;

  ... getters/setters elided
}

public class QueryAttachment {
  @Facebook("object_id")
  private String objectId;

  ... getters/setters elided
}

Let me know if that solves your problem.

Original comment by mark.a.a...@gmail.com on 31 Mar 2011 at 5:38

GoogleCodeExporter commented 8 years ago
To clarify a bit: in the case of the same FB field name being mapped to 
multiple Java fields the mapper tries to map each field name.  If the mapping 
fails, the field will be null and no exception will be thrown (this is in 
contrast to the normal behavior seen for fields that are not multiple-mapped, 
where an exception is thrown on failed mapping).

Original comment by mark.a.a...@gmail.com on 31 Mar 2011 at 5:40

GoogleCodeExporter commented 8 years ago
I'm sure that solution would work, and I'm already using another workaround to 
coax Facebook into returning consistent results. The underlying problem is with 
the inconsistent JSON that Facebook returns, and is very similar to the problem 
in Issue #76, so I thought you might want to address it as a special case in 
the library code as you did there.

Original comment by blick...@gmail.com on 31 Mar 2011 at 5:46

GoogleCodeExporter commented 8 years ago
I might in the future; thanks for the suggestion.  Once the enhancement was 
added that allows multiple mapping, my plan was to have further wackiness like 
what you're seeing addressed by that rather than special-casing the JSON mapper 
(the existing special-casing has been left intact for backwards compatibility).

But yeah, if FB makes more of a habit of returning inconsistent JSON like this, 
then my hand will be forced and I'll probably make the change directly in the 
JSON mapper.

I'll keep this issue opened for an unschedule future release.  Thanks for 
letting me know about it!

Original comment by mark.a.a...@gmail.com on 31 Mar 2011 at 5:56