bobolounna / restfb

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

Unable to Map User.class to Json #186

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. User user = facebookClient.fetchObject("me", User.class);
2. JsonMapper jsonMapper = new DefaultJsonMapper();             
3. output.println(jsonMapper.toJson(user, true));

What is the expected output? What do you see instead?
The default JsonMapper should map the User class to Json and print this. But 
hometown is has 2 annotations and is unable to map both. 

What version of the product are you using? On what operating system?
1.6.9, CentOS 6 under Tomcat7

Please provide any additional information below.
The error message that is displayed is:
Unable to convert to JSON because multiple @Facebook annotations for the same 
name are present: [hometown]

Original issue reported on code.google.com by peterm...@gmail.com on 29 Apr 2012 at 7:02

GoogleCodeExporter commented 8 years ago
Hm, I have to think about the best way to handle this without adding additional 
complexity (like introducing some way to indicate which field is supposed to be 
used for Java->JSON when the same annotation exists multiple times) - thanks 
for the bug report.

Maybe the simplest is:

If JsonMapper finds multiple annotations for the same field, it checks the 
value of each field.  If there is only one non-null field, JsonMapper will 
marshal that.  If there are multiple non-null fields, JsonMapper will pick a 
field (which one is undefined) to marshal.  What do you think?

Original comment by m...@xmog.com on 3 May 2012 at 1:50

GoogleCodeExporter commented 8 years ago
Fixed in 
https://github.com/revetkn/restfb/commit/0de05fff2f57f9508f5f10bb686d19d3cc2c582
2.

The band-aid was that the mapper will selected a field by luck-of-the-draw.  I 
would like to improve this later but have to make sure it's doable without 
adding too much complexity to the public API.

Original comment by m...@xmog.com on 1 Sep 2012 at 4:42