使用Spring data jpa 的 Projections,它会创建定义的接口的代理示例, fastjson会转换失败

91zkwejq  于 2021-11-27  发布在  Java
关注(0)|答案(2)|浏览(249)

错误内容:
Could not write JSON: write javaBean error, fastjson version 1.2.41, class org.springframework.data.domain.PageImpl, write javaBean error, fastjson version 1.2.41, class com.sun.proxy.$Proxy119, fieldName : 0; nested exception is com.alibaba.fastjson.JSONException: write javaBean error, fastjson version 1.2.41, class org.springframework.data.domain.PageImpl, write javaBean error, fastjson version 1.2.41, class com.sun.proxy.$Proxy119, fieldName : 0

下面是部分代码

public interface OperationPJ {
    String getId();
    String getState();
}
public interface OperationRepository extends CrudRepository<Operation,String> {
    Page<OperationPJ> findByCarInfoNo(String carInfoId, Pageable pageable);
}
@Service
public class OperationService {
    @Autowired
    private OperationRepository operationRepository;

    public Page<OperationPJ> findByCarInfoNo(String carInfoNo, Pageable pageable) {
        return operationRepository.findByCarInfoNo(carInfoNo, pageable);
    }
}

spring data jpa projections文档
https://docs.spring.io/spring-data/jpa/docs/2.0.2.RELEASE/reference/html/#projections

mbyulnm0

mbyulnm01#

能提供能重现问题的testcase么?

jgzswidk

jgzswidk2#

这个问题解决了吗?我用的1.2.62版本依然报错,OperationPJ应该是动态代理对象

相关问题