我试图序列化这个内部类
static class functionMessage{
String type = "function";
String id;
String function;
Object parameters;
public functionMessage(String ID, String Function, Boolean Parameters) {
this.id = ID;
this.function = Function;
this.parameters = (Boolean) Parameters;
}
}使用
new flexjson.JSONSerializer().exclude("*.class").serialize(
new functionMessage(
"container",
"showContainer",
Boolean.TRUE
)
) 但只有{}才能被重建。
如果我试图在每个成员变量之前添加public,则会出现以下错误:
flexjson.JSONException: Error trying to deepSerialize
Caused by: java.lang.IllegalAccessException: Class flexjson.BeanProperty can not access a member of class with modifiers "public"我试着遵循示例,但它并没有说明Person是如何构造的,我也不知道如何使类成为static内部类,因为我对Java还很陌生。
我还试着阅读谷歌给出的所有解决方案,但仍然没有。
flexjson.JSONSerializer()如何返回static内部类的所有成员变量?
发布于 2014-01-11 20:03:33
但只有{}是被重建的。
显然,flexjson使用getter解析JSON元素。你的课上没有。
只需添加相应的getter
public String getType() {
return type;
}
public String getId() {
return id;
}
public String getFunction() {
return function;
}
public Object getParameters() {
return parameters;
}至于
如果我试图在每个成员变量之前添加public,则会出现以下错误:
这是因为您的static类具有默认的包访问权限,因此它的字段对其声明的包之外的任何类都是不可见的。
https://stackoverflow.com/questions/21067147
复制相似问题