我希望我的类可以通过getter / setter方法而不是字段声明自动序列化。
class SerializationTest{
String notSerialized = "not serialized";
public String getSerialized() {
return "serialized";
}
}
serialized
应该在生成的json中可见,而notSerialized
则不应该。{/ p>
答案 0 :(得分:0)
您可以使用@JsonAutoDetect
注释指定在类中序列化的内容。像这样:
@JsonAutoDetect( fieldVisibility = Visibility.NONE,
getterVisibility = Visibility.PUBLIC_ONLY,
isGetterVisibility = Visibility.PUBLIC_ONLY,
setterVisibility = Visibility.PUBLIC_ONLY)
class SerializationTest{
String notSerialized = "not serialized";
String getSerialized() {
return "serialized";
}
}
答案 1 :(得分:0)
您可以更改可见性设置,或者只是添加注释以指示要检测非公共字段:
@JsonProperty
String notSerialized = "not serialized";