首页 > 解决方案 > 如何在非持久实体中序列化嵌套的 PersistentEntityResource

问题描述

我希望PersistentEntityResource在非持久实体中序列化嵌套。资源在没有嵌套的情况下返回时被序列化,因此该实体中可能没有问题。

这是我试图返回的实体的虚拟 + 包括持久实体在内的嵌套类

class ReturnedEntityDummy {
    List<resourceWrapperDummy> dummy

    ReturnedEntityDummy(List<resourceWrapperDummy> versions){
        this.dummy = dummy
    }
}
class resourceWrapperDummy<T> {
    PersistentEntityResource content
    Integer position

    resourceWrapperDummy(PersistentEntityResource content, Integer position) {
        this.content = content
        this.position = position
    }
}

最后一个类的PersistentEntityResource内部是我想要序列化的类,这是我尝试返回时收到的错误消息ReturnedEntityDummy

Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Failed to specialize base type org.springframework.data.mapping.PersistentEntity<java.lang.Object,org.springframework.data.mapping.PersistentProperty<java.lang.Object>> as org.springframework.data.jpa.mapping.JpaPersistentEntityImpl, problem: Type parameter #2/2 differs;

标签: javaspringserializationjackson

解决方案


推荐阅读