简体   繁体   中英

cannot serialize FB object: Attempted to serialize java.lang.Class

I try to parse a FB GraphObject to string:

The code crashes here: Gson gson = new Gson(); FbDataToServer fbDataToServer = new FbDataToServer(); fbDataToServer.fbJson = gson.toJson(graphObject);

this is the object:

GraphObject{graphObjectClass=GraphObject, state={"id":"ddd","work":[{"employer":{"id":"dddddd","name":"dddd"},"start_date":"2013-09-19"},...[{"id":"209889829023118","name":"Landmark"}],"name":"Architecture"}],"paging":{"next":"https:\/\/graph.facebook.com\/v1.0\/685560152\/interests?access_token=CAAB3f7ftw4MBABHRExfffdteQ....5VvJwDc3onA3aq1gZDZD&limit=25&offset=25&__after_id=enc_AewtXh6lIg-eFjFLaQHEZ....D9efdfdTcUk9aAORxo_iL_dNTLLP49q"}},"likes":{"data":[{"id":"593290680744992","category":"Spas\/beauty\/personal care","created_time":"2014-08-12T14:43:48+0000","category_list":[{"id":"200814353265561","name":"Spa"},{"id":"144873802247220","name":"Cosmetics & Beauty Supply"}],"name":"Zen Spa"},{"id":"123194331045896","created_time":"2014-08-10T10:35:31+0000","category":"Health\/beauty","name":"SABON - סבון"},.....m{"id":"110344025691431","created_time":"2014-05-12T18:19:55+0000","category":"Local business","name":"סקי בגלבוע"},{"id":"240049663793","created_time":"2014-05-07T06:05:15+0000","category":"Tv channel","name":"חדשות10"},{"id":"154815284659799","created_time":"2014-05-02T13:59:52+0000","category":"Company","name":"חריש הירוקה"}],"paging":{"cursors":{"after":"MTU0O....NjU5Nzk5","before":"NTkzM...NzQ0OTky"},"next":"https:\/\/graph.facebook.com\/v1.0\/685560152\/likes?access_token=CAAB3f7ftw.....c3onA3aq1gZDZD&limit=25&after=MTU0....5Nzk5"}}}}

with this error:

08-12 23:59:48.936: E/AndroidRuntime(409): FATAL EXCEPTION: main
08-12 23:59:48.936: E/AndroidRuntime(409): Process: com.example.manyexampleapp, PID: 409
08-12 23:59:48.936: E/AndroidRuntime(409): java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: com.facebook.model.GraphObject. Forgot to register a type adapter?
08-12 23:59:48.936: E/AndroidRuntime(409):  at com.google.gson.internal.bind.TypeAdapters$1.write(TypeAdapters.java:67)
08-12 23:59:48.936: E/AndroidRuntime(409):  at com.google.gson.internal.bind.TypeAdapters$1.write(TypeAdapters.java:61)
08-12 23:59:48.936: E/AndroidRuntime(409):  at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
08-12 23:59:48.936: E/AndroidRuntime(409):  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
08-12 23:59:48.936: E/AndroidRuntime(409):  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)

Method)

How can I fix this?

Exclude the unserializable fields like obviously "graphObjectClass" as described in Gson: How to exclude specific fields from Serialization without annotations .

EDIT I missed to notice that you try to serialize a completely unserializable class. You have to create a new serializable class and populate it with the FB data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM