org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Unrecognized field "rate" (class com.itjcloud.teachercenter.common.module.lesson.VO.resource.QuestionVO), not marked as ignorable (61 known properties: "labelStatus", "errorRate", "questionIndex", "score", "sourceId", "videoAnswer", "id", "browseNum", "sort", "halfScore", "isCollect", "questionId", "origin", "catalogueList", "auditStatus", "totalScore", "source_name", "parse", "labelAuditTime", "subjectCode", "knowledgeList", "answer", "questionType", "originalScore", "refuseDesc", "sourceName", "paperId", "auditTime", "cateId", "degree", "composeSource", "hearAudioInfo", "videoAnswerList", "title", "uploadType", "discuss", "method", "createTime", "knowledgeNames", "questionTypeName", "analyse", "label", "isDelete", "degreeName", "questionStatus", "cateName", "cate_name", "collectNum", "auditor", "useNum", "hearAudio", "source", "child", "options", "questionSource", "date", "time", "objectiveAnswer", "labelAuditor", "uploadSource", "weigh"])
at [Source: (byte[])"["com.itjcloud.teachercenter.common.module.lesson.VO.resource.PaperVO",{"composeSource":"资源总库","resourceId":420940082078339072,"id":419078090606514176,"paperName":"物质的量 摩尔质量","totalScore":["java.math.BigDecimal",0],"questionVOS":["java.util.ArrayList",[["com.itjcloud.teachercenter.common.module.lesson.VO.resource.QuestionVO",{"composeSource":"资源总库","id":419077290517872640,"source":"资源总库","sort":1,"score":["java.math.BigDecimal",0],"totalScore":["java.util."[truncated 207789 bytes]; line: 1, column: 7741] (through reference chain: com.itjcloud.teachercenter.common.module.lesson.VO.resource.PaperVO["questionVOS"]->java.util.ArrayList[0]->com.itjcloud.teachercenter.common.module.lesson.VO.resource.QuestionVO["rate"]); nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "rate" (class com.itjcloud.teachercenter.common.module.lesson.VO.resource.QuestionVO), not marked as ignorable (61 known properties: "labelStatus", "errorRate", "questionIndex", "score", "sourceId", "videoAnswer", "id", "browseNum", "sort", "halfScore", "isCollect", "questionId", "origin", "catalogueList", "auditStatus", "totalScore", "source_name", "parse", "labelAuditTime", "subjectCode", "knowledgeList", "answer", "questionType", "originalScore", "refuseDesc", "sourceName", "paperId", "auditTime", "cateId", "degree", "composeSource", "hearAudioInfo", "videoAnswerList", "title", "uploadType", "discuss", "method", "createTime", "knowledgeNames", "questionTypeName", "analyse", "label", "isDelete", "degreeName", "questionStatus", "cateName", "cate_name", "collectNum", "auditor", "useNum", "hearAudio", "source", "child", "options", "questionSource", "date", "time", "objectiveAnswer", "labelAuditor", "uploadSource", "weigh"])
at [Source: (byte[])"["com.itjcloud.teachercenter.common.module.lesson.VO.resource.PaperVO",{"composeSource":"资源总库","resourceId":420940082078339072,"id":419078090
这个异常的信息显示,在反序列化JSON字符串时,发现了未知的字段“rate”,导致反序列化失败。这种情况一般是因为Java对象和JSON数据不一致导致的。
解决这个问题的方法有:
1. 检查程序中使用的Java对象和JSON字符串之间的映射关系是否正确,确保Java对象中的所有字段都在JSON字符串中存在。
2. 使用Jackson等JSON库提供的注解,如@JsonInclude、@JsonIgnoreProperties等,标注哪些属性需要序列化和反序列化,并忽略未知属性。
3. 检查JSON字符串格式是否正确,可能是由于JSON字符串中存在语法错误或数据格式不匹配导致的反序列化失败。
4. 将异常信息打印到日志中,结合调用栈和代码逻辑进行排查,找出引起异常的具体原因。
总之,对于这种反序列化异常,需要仔细检查Java对象和JSON字符串之间的映射关系,同时加强异常日志记录和排查能力,及时定位和解决问题。
领取专属 10元无门槛券
私享最新 技术干货