我正在使用 Spring Rest 和 Jackson 来生成 json。对于类(class)国家
public class Country extends AbstractPersistable<Long> {
private String name;
private String code2;
private String code3;
public Country() {
}
public Country(String name, String code2, String code3) {
...
}
...
}
例如,我得到,
{
"id" : 1,
"name" : "Afghanistan",
"code2" : "AF",
"code3" : "AFG",
**"new" : false**
}
对于某些类,我得到一个意外的"new"字段,该字段始终设置为 false。我怀疑这与参数化构造函数有关,但这只是一个猜测。有想法吗?
最佳答案
类 AbstractPersistable
有一个名为 isNew
的公共(public)方法,由接口(interface) Persistable
(文档 here )指定。
如果您不想在 JSON 中使用此类属性,则必须忽略此类属性,例如使用 annotation类中的 JsonIgnoreProperties
。
关于java - Jackson 生成意外的 "new"字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18314576/