问题描述
我试图将rest-facebook响应转换为Post类对象,如下所示:
Post post = gson。 fromJson(restFBResponse.toString(),Post.class);
其中, restFBResponse
是来自Facebook的信息。但是它会导致错误:
线程main中的异常java.lang.IllegalArgumentException:class com.restfb.types。 Post声明了多个名为类型为
的JSON字段,我认为这是由于:
1)
class Post扩展NamedFacebookType {
@Facebook
private String type;
//和更多类成员
}
2)
class名称FacebookTypeextends FacebookType {
//少数类成员
}
3)
class FacebookType实现Serializable {
@ Facebook
私有字符串类型;
//和更多类成员
}
因此, private String type;
被声明了两次,在 class Post
和 class FacebookType
。
$ b $ 1)如果这种重新声明发生在子类中,是不是应该被覆盖?和
2)我该如何克服这个错误 class com.restfb.types.Post声明了多个名为type
解决方案
我刚写了我自己的类没有扩展名,发现没有其他更好的选项。 b
public class MyPost {
@Facebook
private String type;
public String getType(){
返回类型;
}
public void setType(String type){
this.type = type;
}
}
I'm trying to convert rest-facebook response to a Post class object as follows:
Post post = gson.fromJson(restFBResponse.toString(), Post.class);
where,
restFBResponse
is a post from Facebook. But it is resulting into error:
Exception in thread "main" java.lang.IllegalArgumentException: class com.restfb.types.Post declares multiple JSON fields named type
I think this is due to:
1)
class Post extends NamedFacebookType{
@Facebook
private String type;
//and some more class members
}
2)
class NamedFacebookType extends FacebookType {
//few class members
}
3)
class FacebookType implements Serializable {
@Facebook
private String type;
//and some more class members
}
So,
private String type;
is being declared twice, in class Post
and class FacebookType
.
1) If such re-declaration occurs in subclass,should it not be overridden? and
2) How can I overcome this error
class com.restfb.types.Post declares multiple JSON fields named type
?
解决方案
I just written my own class without extension, found no other better option..
public class MyPost{
@Facebook
private String type;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
这篇关于Solr-java错误:类com.restfb.types.Post声明了多个名为type的JSON字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!