No serializer found for class org 问题解决 一定要细心 !!也许问题根本不是这个。

本文探讨了在使用Spring Data时遇到的JSON序列化错误,具体表现为找不到序列化器的问题,并给出了通过调整实体类和使用@JsonIgnore注解来解决审计字段序列化异常的方法。

今天一直在报这个错"Type definition error: [simple type, class org.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessorCustomAnnotationTransactionAttributeSource];nestedexceptioniscom.fasterxml.jackson.databind.exc.InvalidDefinitionException:Noserializerfoundforclassorg.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessorCustomAnnotationTransactionAttributeSource]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessorCustomAnnotationTransactionAttributeSource];nestedexceptioniscom.fasterxml.jackson.databind.exc.InvalidDefinitionException:Noserializerfoundforclassorg.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessorCustomAnnotationTransactionAttributeSource and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.sinosoft.web.rest.util.TmsInfoModel[“data”]->com.sun.proxy.$Proxy384[“advisors”]->org.springframework.aop.support.DefaultPointcutAdvisor[4]->org.springframework.aop.support.DefaultPointcutAdvisor[“advice”]->org.springframework.transaction.interceptor.TransactionInterceptor[“transactionAttributeSource”])",

查了之后说是实体类没有set方法,就是忘记set和get了,但是检查我自己是有的。还有的是说是json对象保存数据时候对时间类型转换有问题,原因是实体类继承AbstractAuditingEntity审计功能,其中的createdDate和lastModifiedDate字段是Instant类型的,json对其进行序列化和反序列化会报错。解决办法在审计类的字段加上@JsonIgnore注解就解决了。

最后这些问题都大概的查之后,只是因为我在接受的对象的时候应该用tmsInfoModel.setData(保存数据的表名类)不应该是数据库的repository类 。是tmsInfoModel.setData(ltYearStudyFlag);
而不是tmsInfoModel.setData(ltYearStudyFlagRepository);

附一段代码 :

/**
* 保存记录
* @return
*/
public TmsInfoModel saveYearFlagInfo(JSONObject body){
TmsInfoModel tmsInfoModel = new TmsInfoModel();
Integer bookCount = body.getInteger(“bookCount”);
Integer cityCount = body.getInteger(“cityCount”);
Integer studyTime = body.getInteger(“studyTime”);
Integer classCount = body.getInteger(“classCount”);
String goalText = body.getString(“goalText”);
List infos = ltYearStudyFlagRepository.findAllByTrainCode(PubFun.getCurrentUser());
if (infos.size() > 0) {
tmsInfoModel.setData(infos.get(0));
tmsInfoModel.setMsg(“已经存在该数据”);
}else{
LtYearStudyFlag ltYearStudyFlag = new LtYearStudyFlag();
ltYearStudyFlag.setTrainCode(PubFun.getCurrentUser());
ltYearStudyFlag.setBookCount(bookCount);
ltYearStudyFlag.setCityCount(cityCount);
ltYearStudyFlag.setStudyTime(studyTime);
ltYearStudyFlag.setClassCount(classCount);
ltYearStudyFlag.setGoalText(goalText);
ltYearStudyFlag.setCreatedDate(PubFun.getCurrentDate());
ltYearStudyFlag.setLastModifiedDate(PubFun.getCurrentDate());
ltYearStudyFlagRepository.save(ltYearStudyFlag);
tmsInfoModel.setMsg(“该用户数据保存成功”);
tmsInfoModel.setData(ltYearStudyFlag);//很关键的一行
}
return tmsInfoModel;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值