Facebook からクエリ応答を取得し、それをユーザー定義クラスにマップしようとしています。
私は次のクラスを持っています:
class FBStory {
@Field
private String application_id;
@Field
private String application_name;
@Field
private String caption;
@Field
private String created_time;
@Field
private String description;
@Field
private String from;// user_Id
@Field
private String message;
@Field
private String name;
@Field("objectId")
private String object_id;
@Field
private String privacy;
@Field("statusType")
private String status_type;
@Field
private String story;
@Field("storyId")
private String id;
@Field("storyUrl")
private String link;
@Field
private String type;
@Field
private String updated_time;
@Field
private Set<CommentInfo> comments = new HashSet<CommentInfo>();//set of comment Id
@Field
private Set<String> likes = new HashSet<String>();
@Field("storyTags")
private Set<String> story_tags = new HashSet<String>();
}
そして、クエリに対する Facebook の応答は次のとおりです。
Post[actions=[] application=null attribution=null caption=null comments=Comments[count=0 data=[]] createdTime=Mon Apr 01 08:16:28 IST 2013 description=null from=CategorizedFacebookType[category=null id=100000363414872 metadata=null name=Nitin Thokare type=null] icon=null id=100000363414872_555878751100900 likes=null likesCount=null link=null message=null messageTags={} metadata=null name=null objectId=null picture=null place=null privacy=Privacy[deny=null description=null friends=null networks=null value=] properties=[] source=null to=[] type=status updatedTime=Mon Apr 01 08:16:28 IST 2013 withTags=[]]
以下を使用して、上記の応答を上記のクラスのオブジェクトに変換しようとしていました。
storyObj = gson.fromJson(restFBResponse.toString(), SolrFBStoryDoc.class);
ただしgson.fromJson()
、最初のパラメーターは StringJSON
形式にする必要があります。したがって、上記のコード行でエラーが発生します。
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 5
restFBResponse
適切な文字列に変換し、Json
最初のパラメーターとしてに渡す方法はありますgson.fromJson()
か?