我有一个AbstractEntity
用属性调用的基本 JPA 实体code
,我还有大量其他 JPA 实体(ProductEntity
、CategoryEntity
、UserEntity
等),每个实体都从AbstractEntity
.
现在一些实体有对其他实体的引用,例如CategoryEntity
有一个名为的属性parentCategory
或ProductEntity
有一个类别的集合 ( categories
)。
现在我想用 jackson 序列化 a ProductEntity
,但是每当一个属性是类型时,AbstractEntity
我希望它只打印 the而不打印code
其他任何东西。
我的解决Serializer
方案是为. 相反,我想要的是:AbstractEntity
ProductEntity
AbstractEntity
objectMapper.writeValueAsString(product)
code
{
code: 'abc',
category : 'categoryA',
price : '12 $',
active : true
}
有没有办法告诉杰克逊仅将我的自定义序列化程序用于字段而不是对象本身?顺便说一句,我不能真正使用注释,因为我无权访问代码,就像我说的类真的很多。