无法序列化FB对象:尝试序列化java.lang.Class

时间:2014-08-12 21:06:36

标签: java android json facebook gson

我尝试将FB GraphObject解析为string:

代码崩溃在这里:                         Gson gson = new Gson();                         FbDataToServer fbDataToServer = new FbDataToServer();                         fbDataToServer.fbJson = gson.toJson(graphObject);

这是对象:

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"}}}}

出现此错误:

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)

方法)

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

排除不可序列化的字段,比如显然" graphObjectClass"如Gson: How to exclude specific fields from Serialization without annotations中所述。

编辑我没想到你试图序列化一个完全不可序列化的类。您必须创建一个新的可序列化类并使用FB数据填充它。