【发布时间】:2019-09-09 18:27:12
【问题描述】:
以下结果会导致 MappingException。我需要改变我的设计吗?
public class Foo extends Bar {
// if class == Foo do not send this over the wire
@JsonProperty(access = Access.WRITE_ONLY)
public List<X> myList;
}
public class Bar {
// if class == Bar send this over the wire
public List<X> myList;
public void methodsThatAccessMyList() {
// multiple methods exists in here accessing myList
// also, other classes exist extending bar,
//so moving these to the children will result in duplicate code
}
}
但是,我需要子类的 json 属性,以防止子类通过网络传输该字段。
我需要改变什么来防止不明确的映射?
org.springframework.data.mapping.MappingException:不明确的字段 检测到映射!都受保护的 java.util.List ...和 @com.fasterxml.jackson.annotation.JsonProperty(index=-1, access=WRITE_ONLY, value="", defaultValue="", required=false)protected java.util.List ...映射到相同的字段名...!消除歧义 @Field 注解!
【问题讨论】:
标签: java inheritance jackson spring-data spring-data-mongodb