0

我有一个AbstractEntity用属性调用的基本 JPA 实体code,我还有大量其他 JPA 实体(ProductEntityCategoryEntityUserEntity等),每个实体都从AbstractEntity.

现在一些实体有对其他实体的引用,例如CategoryEntity有一个名为的属性parentCategoryProductEntity有一个类别的集合 ( categories)。

现在我想用 jackson 序列化 a ProductEntity,但是每当一个属性是类型时,AbstractEntity我希望它只打印 the而不打印code其他任何东西。

我的解决Serializer方案是为. 相反,我想要的是:AbstractEntityProductEntityAbstractEntityobjectMapper.writeValueAsString(product)code

{
 code: 'abc',
 category : 'categoryA',
 price : '12 $',
 active : true
}

有没有办法告诉杰克逊仅将我的自定义序列化程序用于字段而不是对象本身?顺便说一句,我不能真正使用注释,因为我无权访问代码,就像我说的类真的很多。

4

0 回答 0