首页 > 解决方案 > Java - 无法从 START_OBJECT 令牌中反序列化 java.lang.Integer 的实例?

问题描述

当我尝试将POST一个人反对 3rd 方 API 时,我的应用程序中出现以下错误:

Can not deserialize instance of java.lang.Integer out of START_OBJECT token
 at [Source:
 (through reference chain: Person["postcode"]

我认为问题在于我将邮政编码作为整数,而在 API 合同中它是一个 json 数组。

如何Json array在我的 Java POJO 中将 a 表示为一个字段?

POJO:

public class Person {

    @JsonProperty
    private Integer id;

    @JsonProperty("postcode")
    private Integer postcode;
    
    // other fields...
    
    }

即在来自成功 POST 的 JSON 响应中,该"postcode"字段为:

"postcode": [],

标签: javaarraysjsonserializationpojo

解决方案


推荐阅读