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;
...
}