首页 > 解决方案 > fastxml.jackson 在 Spring Boot 中解析错误的类

问题描述

我发现 fastxml.jackson 在我的项目中解析了错误的类。我有这个控制器方法:

@PutMapping
public Course updateCourse(@RequestBody CourseDto course) {
    LoggedUser.logIn(authenticationFacade.getAuthentication().getName());
    Course courseEntity = converter.convert(course);
    return courseService.updateCourse(courseEntity);
}

但是当我向 API 发送 PUT 请求时,我得到了这个日志:

2018-12-16 13:36:58.339  WARN 9400 --- [nio-8080-exec-4] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unresolved forward references for: ; nested exception is com.fasterxml.jackson.databind.deser.UnresolvedForwardReference: Unresolved forward references for: 
 at [Source: (PushbackInputStream); line: 93, column: 1]Object id [3] (for `server.crm.entities.Course`) at [Source: (PushbackInputStream); line: 27, column: 24], Object id [3] (for `server.crm.entities.Course`) at [Source: (PushbackInputStream); line: 46, column: 24], Object id [3] (for `server.crm.entities.Course`) at [Source: (PushbackInputStream); line: 65, column: 24], Object id [3] (for `server.crm.entities.Course`) at [Source: (PushbackInputStream); line: 84, column: 24].]

您可以看到它尝试解析 server.crm.entities.Course 而不是 CourseDto,就像我在 @RequestBody 之后所做的那样。

你能帮我解决这个问题吗?

标签: javaspring-bootjackson

解决方案


推荐阅读