spring-attic / spring-social-facebook

Facebook API binding and connect support.
http://projects.spring.io/spring-social-facebook
Apache License 2.0
248 stars 269 forks source link

Error deserializing data from Facebook while parsing org.springframework.social.facebook.api.Page["likes"] #209

Closed aludwiko closed 7 years ago

aludwiko commented 8 years ago

After invoking: facebook.likeOperations().getPagesLiked(); I'm facing exception below:

2016-07-14 08:54:49.592 ERROR 21687 --- [nio-8080-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.social.UncategorizedApiException: Error deserializing data from Facebook: Can not deserialize instance of int out of START_OBJECT token
 at [Source: [....]; line: 1, column: 394] (through reference chain: java.util.ArrayList[0]->org.springframework.social.facebook.api.Page["likes"])] with root cause

com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of int out of START_OBJECT token
 at [Source: [{"id":"532893790123811","name":"Pantin.pl","category":"Shopping/Retail","location":{"city":"Warszawa","street":"Zaborowska 3/102","zip":"01-462"},"website":"http://pantin.pl","picture":{"data":{"is_silhouette":false,"url":"https://scontent.xx.fbcdn.net/v/t1.0-1/p50x50/10891487_769435389802982_5405033680722684296_n.jpg?oh=ecaf9d77281254d9de6a1f2a8de10fae&oe=583409E6"}},"phone":"537 442 953","likes":{"data":[{"name":"Doktor Mama","id":"1427821997450768"},{"name":"Magazyn Świat Zabawek","id":"125452894212716"},{"name":"Schwytane chwile","id":"476955545722197"},{"name":"Książki na czacie","id":"517964151549514"},{"name":"Small foot - Legler","id":"1071869769504821"},{"name":"Igroteco Ltd","id":"1665869563685804"},{"name":"Stowarzyszenie Rodziców Dzieci Niepełnosprawnych \"Światełko\"","id":"123799804481600"},{"name":"Happy Hooligans","id":"216302488420163"},{"name":"pus.pl - Wydawnictwo Epideixis","id":"171151762895997"},{"name":"Cała Polska czyta dzieciom","id":"636470099709266"},{"name":"Czym zająć Malucha?","id":"443914889018247"},{"name":"Hubelino","id":"140807259303984"},{"name":"Kreatywnie w domu","id":"1418189921729095"},{"name":"Kusiątka","id":"463673670401599"},{"name":"Zabawkator","id":"485590371540932"},{"name":"Totschooling","id":"461176194009376"},{"name":"Weplay","id":"174388215928887"},{"name":"Mamablizniacza blog","id":"128992780598574"},{"name":"Pirx3D","id":"476926302357733"},{"name":"Fun at Home with Kids","id":"128903633948378"},{"name":"kandipatterns.com","id":"390681538992"},{"name":"Spielwarenmesse","id":"160932500623156"},{"name":"WEDGiTS™ Building Blocks from ImagAbility, Inc.","id":"88347429659"},{"name":"Kid's Biz Fair","id":"345263512215444"},{"name":"Triqo","id":"71896418948"}],"paging":{"cursors":{"before":"MTQyNzgyMTk5NzQ1MDc2OAZDZD","after":"NzE4OTY0MTg5NDgZD"}}},"checkins":0,"cover":{"cover_id":"826588670754320","offset_x":0,"offset_y":0,"source":"https://scontent.xx.fbcdn.net/v/t1.0-9/s720x720/11209759_826588670754320_3842549365222782651_n.jpg?oh=20d26e5bbface546d157d70d820373aa&oe=582A3265","id":"826588670754320"}}]; line: 1, column: 394] (through reference chain: java.util.ArrayList[0]->org.springframework.social.facebook.api.Page["likes"])
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148) ~[jackson-databind-2.6.7.jar:2.6.7]
    at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:857) ~[jackson-databind-2.6.7.jar:2.6.7]
    at com.fasterxml.jackson.databind.deser.std.StdDeserializer._parseInteger(StdDeserializer.java:460) ~[jackson-databind-2.6.7.jar:2.6.7]
    at com.fasterxml.jackson.databind.deser.std.NumberDeserializers$IntegerDeserializer.deserialize(NumberDeserializers.java:309) ~[jackson-databind-2.6.7.jar:2.6.7]
    at com.fasterxml.jackson.databind.deser.std.NumberDeserializers$IntegerDeserializer.deserialize(NumberDeserializers.java:287) ~[jackson-databind-2.6.7.jar:2.6.7]
    at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:520) ~[jackson-databind-2.6.7.jar:2.6.7]
    at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:101) ~[jackson-databind-2.6.7.jar:2.6.7]
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:258) ~[jackson-databind-2.6.7.jar:2.6.7]
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:125) ~[jackson-databind-2.6.7.jar:2.6.7]
    at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:245) ~[jackson-databind-2.6.7.jar:2.6.7]
    at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:217) ~[jackson-databind-2.6.7.jar:2.6.7]
    at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:25) ~[jackson-databind-2.6.7.jar:2.6.7]
    at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1511) ~[jackson-databind-2.6.7.jar:2.6.7]
    at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1136) ~[jackson-databind-2.6.7.jar:2.6.7]

org.springframework.social.facebook.api.Page#likes is not an int in facebook api. In raw JSON there is something like this:

"likes": {
        "data": [
          {
            "name": "Crossweb",
            "id": "478521985506897"
          },
          {
            "name": "AgileByExample",
            "id": "397101886981999"
          }
        ],
        "paging": {
          "cursors": {
            "before": "NDc4NTIxOTg1NTA2ODk3",
            "after": "Mzk3MTAxODg2OTgxOTk5"
          }
        }

Because this is org.springframework.social.facebook.api.PagedList, I suppose, that likes field should be removed from org.springframework.social.facebook.api.Page. If there is a need to get pages liked by some page we can achieve this using current functionality:

PagedList<Page> myLikes = facebook.likeOperations().getPagesLiked();
String pageId = myLikes.get(0).getId();
PagedList<Reference> likedByThisPage = facebook.likeOperations().getLikes(pageId);
aludwiko commented 8 years ago

Actually there is a better way to fix this, but it requires to refactor field name from likes to fanCount. PR is updated.

volvotrax commented 7 years ago

Thank you for your fix. It was helpful.