springMVC返回jean错误

2020-07-05  本文已影响0人  轻云绿原

Account

public class Account implements Serializable {
    private Integer id;
    /**
     * 用户姓名
     */
    private String username;
    /**
     * 余额
     */
    private Float balance;
    /**
     * 用户
     */
    private User user;
}

User

public class User implements Serializable {
    private Integer id;
    /**
     * 真实姓名
     */
    private String name;
    /**
     * 头像
     */
    private String avatar;
}

在springMVC里直接返回Account时错误

前提

使用mybatis查询Account时,使用fetchType="lazy"

错误

Type definition error: [simple type, class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory$EnhancedResultObjectProxyImpl]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory$EnhancedResultObjectProxyImpl and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.ppf.domain.Account_$$_jvst37e_0["handler"])

解决

只要在Account类前加JsonIgnoreProperties(value = {"handler"})就行了

@JsonIgnoreProperties(value = {"handler"})
public class Account implements Serializable {
    private Integer id;
     ...
}
上一篇下一篇

猜你喜欢

热点阅读