首页 > 解决方案 > Jackson 错误解析器尝试解析子类型,但我的类是简单的 POJO

问题描述

味精错误:

{
    "@class": "java.util.LinkedHashMap",
    "timestamp": [
        "java.util.Date",
        "2018-10-04T17:12:35.742+0000"
    ],
    "status": 400,
    "error": "Bad Request",
    "message": "JSON parse error: Missing type id when trying to resolve subtype of [simple type, class br.com.adtsys.ciee.auth.user.data.request.LoginRequest]: missing type id property '@class'; nested exception is com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class br.com.adtsys.ciee.auth.user.data.request.LoginRequest]: missing type id property '@class'\n at [Source: (PushbackInputStream); line: 4, column: 1]",
    "path": "/auth/login"
}

但我的课是一个简单的 POJO

@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class LoginRequest implements Serializable {

    private String username;
    private String password;
}

该对象是我的控制器中的一个参数,我在其中对 POST 方法进行请求,并且该对象使用 @Body 注释进行注释,当我调用其余端点时,spring 尝试在我的对象中转换我的 JSON,但发生了该错误。我正在使用嵌入在 Spring Boot 版本 2.0.5 中的 jackson 库,在我将 spring-boot 版本 1.5.3 升级到 2.0.5 后开始发生该错误。我已经搜索过这个问题,但不幸的是直到现在什么都没有。有人知道这个问题。

标签: javaspringjackson-databind

解决方案


推荐阅读