Results 1 to 10 of 11

Thread: Deserialization error when getting Music likes from Facebook

Hybrid View

  1. #1

    Default 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. #2

    Default

    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.

  3. #3
    Join Date
    Aug 2004
    Posts
    1,070

    Default

    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.
    Craig Walls
    Spring Social Project Lead

  4. #4
    Join Date
    Aug 2004
    Posts
    1,070

    Default

    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.
    Craig Walls
    Spring Social Project Lead

  5. #5
    Join Date
    Aug 2004
    Posts
    1,070

    Default

    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.
    Craig Walls
    Spring Social Project Lead

  6. #6
    Join Date
    Oct 2011
    Location
    London, UK
    Posts
    27

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •