今天一直在报这个错"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;
}
本文探讨了在使用Spring Data时遇到的JSON序列化错误,具体表现为找不到序列化器的问题,并给出了通过调整实体类和使用@JsonIgnore注解来解决审计字段序列化异常的方法。
2959

被折叠的 条评论
为什么被折叠?



