1

当我尝试使用数组反序列化 JSON 时,出现以下错误:

Root name 'countries' does not match expected ('Country[]') for type [array type, component type: [simple type, class com.diveconditions.domain.location.Country]]

我使用以下代码

ObjectMapper mapper = new ObjectMapper();
mapper.configure(Feature.UNWRAP_ROOT_VALUE, true);

Country[] list = mapper.readValue(jsonString, Country[].class);

这里是我的乡村课

@JsonRootName(value = "countries")
public class Country
{
    @JsonProperty("countryName")
    @Getter
    @Setter
    private LocalizedText name;
    @JsonProperty("countryIso2")
    @Getter
    @Setter
    private String twoCharacterIso;
    @Getter
    @Setter
    private UUID uuid;
}

这就是 json 字符串的样子

    {
    "countries": [
        {
            "countryID": "2",
            "countryIso2": "AD",
            "countryName": "Andorra",
            "countryIso3": "AND",
            "is_created": "0",
            "is_updated": "0"
        },
        {
            "countryID": "3",
            "countryIso2": "AE",
            "countryName": "United Arab Emirates",
            "countryIso3": "ARE",
            "is_created": "0",
            "is_updated": ""
        }
    ],
    "downloadCompleted": 1,
    "success": true
}

我究竟做错了什么?

4

0 回答 0