alibaba / fastjson

FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
https://github.com/alibaba/fastjson2/wiki/fastjson_1_upgrade_cn
Apache License 2.0
25.72k stars 6.5k forks source link

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

Open weiwill opened 6 years ago

weiwill commented 6 years ago

错误内容: 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

wenshao commented 6 years ago

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

MroZ11 commented 4 years ago

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