Announcement Announcement Module
Collapse
No announcement yet.
Deserialization error when getting Music likes from Facebook Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Deserialization error when getting Music likes from Facebook

    I've been developing recently on an app that uses Spring Social to connect to Facebook, and up until sometime yesterday it had been going pretty well. Then suddenly the call started failing, for no reason that I could see, and connected to no change of mine that I could isolate.

    Eventually I boiled it down to the simplest case I could--stripping away everything else--and reduced it to the following code...

    Code:
    package com.testproject;
    
    import java.util.List;
    
    import org.springframework.social.facebook.api.Facebook;
    import org.springframework.social.facebook.api.Page;
    import org.springframework.social.facebook.api.impl.FacebookTemplate;
    
    public class FacebookTest {	
    	public static void main(String[] args) {
    		Facebook facebook = new FacebookTemplate("<authtoken pasted here>");
    		List<Page> musicLikes = facebook.likeOperations().getMusic();
    		for (Page p : musicLikes)
    		{
    			System.out.println(p.getName());
    		}
    	}
    }
    ...which still fails with the following error message:

    Code:
    Exception in thread "main" org.springframework.social.UncategorizedApiException: Error deserializing data from Facebook: Can not deserialize instance of java.lang.String out of START_OBJECT token
     at [Source: N/A; line: -1, column: -1]
    	at org.springframework.social.facebook.api.impl.FacebookTemplate.deserializeDataList(FacebookTemplate.java:272)
    	at org.springframework.social.facebook.api.impl.FacebookTemplate.fetchConnections(FacebookTemplate.java:186)
    	at org.springframework.social.facebook.api.impl.FacebookTemplate.fetchConnections(FacebookTemplate.java:179)
    	at org.springframework.social.facebook.api.impl.LikeTemplate.getMusic(LikeTemplate.java:83)
    	at org.springframework.social.facebook.api.impl.LikeTemplate.getMusic(LikeTemplate.java:78)
    	at com.testproject.FacebookTest.main(FacebookTest.java:12)
    Caused by: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
     at [Source: N/A; line: -1, column: -1]
    	at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
    	at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:219)
    	at org.codehaus.jackson.map.deser.std.StringDeserializer.deserialize(StringDeserializer.java:44)
    	at org.codehaus.jackson.map.deser.std.StringDeserializer.deserialize(StringDeserializer.java:13)
    	at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:299)
    	at org.codehaus.jackson.map.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:924)
    	at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObjectUsingNonDefault(BeanDeserializer.java:733)
    	at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:683)
    	at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
    	at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:217)
    	at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:194)
    	at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:30)
    	at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2695)
    	at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:2022)
    	at org.springframework.social.facebook.api.impl.FacebookTemplate.deserializeDataList(FacebookTemplate.java:270)
    	... 5 more
    Stepping through the code, I found that the app did seem to be successfully connecting to Facebook and retrieving the response, with what appeared to be the data of the test Facebook account as I would expect. It was only when Spring Social went to deserialize it that it hit problems.

    As I mentioned above, this was working just dandy for me up until yesterday, which makes me rather suspect that something changed outside my code, but given that I'm rather a novice in this area I wanted to ask first to see if there was anything stupid I was doing that would result in this issue. Is anyone else seeing this problem? Is there a way known to resolve it, or a fix coming?

    Thanks much for any pointers.

  • #2
    Some extra information acquired during debugging, in case it helps:

    Stepping through the code, the precise call that it's dying on in the FacebookTemplate class is:

    Code:
    return (List<T>) objectMapper.readValue(jsonNode, listType);
    Looking at the jsonNode variable, the precise JSON that it's getting back from Facebook is:

    Code:
    [{"id":"5678046685","name":"U2","category":"Musician/band","website":"http://www.u2.com http://www.interscope.com/u2 http://www.myspace.com/u2 http://www.imeem.com/u2music","likes":12968242,"created_time":"2012-08-17T15:58:31+0000","picture":{"data":{"url":"http://profile.ak.fbcdn.net/hprofile-ak-snc4/277150_5678046685_1509018948_q.jpg","is_silhouette":false}}}]
    And that IS exactly the performer that I'd expect to see from that account, so it is clearly contacting Facebook successfully; it's just something in the JSON above that it gets back as a result, and is trying to process, that causes Spring Social to choke somehow.

    Comment


    • #3
      Just a quick reply to let you know that I'm not ignoring this, but I have been out of pocket for the past couple of days. I'm looking into this now and already have some theories. I'll let you know what I find.

      Comment


      • #4
        Well, I thought I had a theory, but that didn't pan out. In fact, I found that everything worked perfectly whenever I called the getMusic() method. I even have U2 as one of my likes (among other musicians).

        What is interesting to me is that the JSON you show for U2 has far more info in it than the JSON that I get for U2. I only get the "name", "id", "category", and "created_time" fields when I ask for music, unless I specifically ask for those other fields. I'm wondering: Did you change anything in Spring Social to have it give you those additional fields? Perhaps something in LikeTemplate?

        In short, I can understand why you're getting the deserialization problem given the JSON that Facebook is returning to you. What I don't understand is why you're getting that JSON instead of the much simpler JSON that I get.

        Comment


        • #5
          Actually, ignore that last bit. I realized that I was looking at the wrong bit of code and, in fact, I the getMusic() method does fetch those other fields. That leaves me stumped as to why it still works for me, but not so much for you. Still digging, though.

          Comment


          • #6
            This is just a hunch, but can I ask does this exception occur when their are multiple likes returned from Facebook, or is does it happen when there is only a single like?

            I had a similar-looking issue with spring-social-lastfm ( https://github.com/michaellavelle/sp...stfm/issues/14 ), where for Jackson Mapper versions > 1.8.5, all my tests failed that had single element lists in the response. Lists with multiple elements were fine, but I had a similar error to yours when only one item in a list was returned:

            org.springframework.http.converter.HttpMessageNotR eadableException: Could not read JSON: Can not deserialize instance of java.util.ArrayList out of FIELD_NAME token.

            I see your exception stack trace is slightly different with String in place of ArrayList, so this may be a completely different issue, but I thought it worth letting you know.

            If this issue has just started occurring, I'm wondering has your version of Jackson changed in your build, or maybe a Facebook account you used that had multiple likes now only has one? If the issue is related to Jackson, I'm wondering if downgrading to 1.8.5 prevents the exception occurring?

            Hope this helps,

            Michael

            Comment


            • #7
              Well, I *sorta* figured it out late last night, but slept on it before responding.

              It seems that the "picture" field used to be a string and now it's an object in the response. So, clearly the deserialization is failing when trying to deserialize an object as a string. What I don't understand, however, is how this was working fine for my simple test, but failing for LarsAnderson's code (which was nearly identical to mine). What's even more interesting is that this morning now even my test is failing (and I *KNOW* it passed yesterday).

              So, clearly there's a deserialization problem on the picture property. I can fix that. I also need to find a Facebook change notification telling about this, because (1) I usually review those closely and I'm surprised I missed it and (2) I'd like to reference it in the change.

              This, of course, also probably means that I'll need to push a Spring Social Facebook 1.0.2 release for the fix. Not a problem, but my question for you is if this is urgent for you (that is, is it in production) so that you need the fix right away? Or can you work off of the same fix in 1.1.0.BUILD-SNAPSHOT so that I can delay the 1.0.2 push until early next week? I can do the fix in a snapshot right away, but if you can wait for a release build until next week, it'd be easier on my already jammed schedule. Let me know.

              Comment


              • #8
                That is, indeed, extremely peculiar...

                No, it's not a super-critical issue; the project is still in dev, not in production, so I can definitely wait for a week or so for it to hit. There are other things I can be focusing on in the interim.

                Thanks very much for tracking this down!

                Comment


                • #9
                  FWIW, I found this reference to the change at https://developers.facebook.com/roadmap/. But, it isn't scheduled until Oct 3, so why is it showing up now?

                  Oh...I see...it's on now, but you can explicitly turn it off in your app settings...until Oct 3rd when it officially changed. I turned off "October 2012 Breaking Changes" for my app and now it works again. So...there's a workaround for you until I get my changes out there.
                  Last edited by habuma; Aug 23rd, 2012, 10:47 AM.

                  Comment


                  • #10
                    I've spent a good chunk of the day shaving yaks in preparation for this fix, but now am about to begin work on it. Unless anyone has any compelling reason to do so otherwise, my intent for Spring Social Facebook 1.0.2 is to simply map the picture.data.url value to the existing String returned from the Page's getPicture() method and to also deprecate that method. Then for 1.1.0, I'll capture the whole picture object and return that in a new getPicture() method.

                    Comment


                    • #11
                      Just so you know, I've applied the changes necessary for this, as well as a handful of other upcoming changes to Facebook's API and have them building to spring-social-facebook version 1.0.2.BUILD-SNAPSHOT.

                      See the following issues for details on the changes:
                      - https://jira.springsource.org/browse/SOCIALFB-92
                      - https://jira.springsource.org/browse/SOCIALFB-93
                      - https://jira.springsource.org/browse/SOCIALFB-94

                      I'd appreciate it if you'd try out 1.0.2.BUILD-SNAPSHOT and let me know if you run into any trouble. My plan is to push the 1.0.2.RELEASE version on Monday, just in time for the Sept 5 breaking changes to be applied at Facebook. (This is, however, the first time I've pushed a release build using a new build procedure, so I may run into some trouble and that might delay the push until Tuesday.)

                      Comment

                      Working...
                      X