下面对象有“私有只读”成员,但是Gson不知道从哪个版本开始,可以正反序列化了。
记得最初需要成员必须具有get和set方法才行。
测试库:Gson 2.4
public class MultiLineAttributes
{
private int timeout;
private MultiLineAttribute[] attributes;
public MultiLineAttributes(int timeout, MultiLineAttribute[] attributes)
{
this.timeout = timeout;
this.attributes = attributes;
}
public int getTimeout()
{
return this.timeout;
}
public MultiLineAttribute[] getAttributes()
{
return this.attributes;
}
public static class MultiLineAttribute
{
private int lineNumber;
private int showModle;
private int showDirect;
private String content;
public MultiLineAttribute(int lineNumber, int showModle, int showDirect, String content)
{
this.lineNumber = lineNumber;
this.showModle = showModle;
this.showDirect = showDirect;
this.content = content;
}
public int getLineNumber()
{
return this.lineNumber;
}
public int getShowModle()
{
return this.showModle;
}
public int getShowDirect()
{
return this.showDirect;
}
public String getContent()
{
return this.content;
}
}
}
也许可以参考这篇文章:?utm_source=tuicool