我正在抽象的文档类中有一个属性字段。对于请求映射,我已经使用jackson JsonTypeInfo来基于“类型”映射到各个对象
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes({ //
@JsonSubTypes.Type(value = Dog.class, name = "dog"), //
@JsonSubTypes.Type(value = Cat.class, name = "cat") //
})
public interface IAnimal {
String getType();
}
public class Dog implements IAnimal {
public String getType() {
return "dog";
}
}
public class Cat implements IAnimal {
public String getType() {
return "cat";
}
}
@Document
public class Animals {
@Id
private String id;
private List<IAnimal> list;
}
我想将文档保存到数据库,但是在调用存储库类上的save方法时,出现以下错误
Caused by: java.lang.StackOverflowError: null
at java.util.HashMap.hash(HashMap.java:339) ~[na:1.8.0_171]
at java.util.HashMap.containsKey(HashMap.java:596) ~[na:1.8.0_171]
at org.springframework.data.mapping.model.AnnotationBasedPersistentProperty.findAnnotation(AnnotationBasedPersistentProperty.java:216) ~[spring-data-commons-1.13.8.RELEASE.jar:na]
at org.springframework.data.mapping.model.AnnotationBasedPersistentProperty.isAnnotationPresent(AnnotationBasedPersistentProperty.java:270) ~[spring-data-commons-1.13.8.RELEASE.jar:na]
at org.springframework.data.mapping.model.AnnotationBasedPersistentProperty.isWritable(AnnotationBasedPersistentProperty.java:200) ~[spring-data-commons-1.13.8.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:428) ~[spring-data-mongodb-1.10.8.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:425) ~[spring-data-mongodb-1.10.8.RELEASE.jar:na]
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:330) ~[spring-data-commons-1.13.8.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:425) ~[spring-data-mongodb-1.10.8.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:527) ~[spring-data-mongodb-1.10.8.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:437) ~[spring-data-mongodb-1.10.8.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:425) ~[spring-data-mongodb-1.10.8.RELEASE.jar:na]
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:330) ~[spring-data-commons-1.13.8.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:425) ~[spring-data-mongodb-1.10.8.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:527) ~[spring-data-mongodb-1.10.8.RELEASE.jar:na]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:437) ~[spring-data-mongodb-1.10.8.RELEASE.jar:na]