提问者:小点点

ObjectMapper-没有从String值反序列化的String参数构造函数/工厂方法


在调用以检索json响应并解析它时遇到问题。

ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);

mapper.convertValue(respDataString, GetListingListResponse.class);

resdataString在哪里

{
    "status": "OK",
    "branch_reference": "148644",
    "listings": []
}

GetListingListResponse.java

@Data
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
        "status",
        "branch_reference",
        "listings"
})
public class GetListingListResponse implements Serializable
{

    @JsonProperty("status")
    private String status;
    @JsonProperty("branch_reference")
    private String branchReference;
    @JsonProperty("listings")
    private List<Listing> listings;

}

Listing.java

@Data
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
        "listing_etag",
        "listing_reference",
        "url"
})
public class Listing implements Serializable
{

    @JsonProperty("listing_etag")
    private String listingEtag;
    @JsonProperty("listing_reference")
    private String listingReference;
    @JsonProperty("url")
    private String url;

}

例外情况

我不知道。有什么问题吗?


共1个答案

匿名用户

目前尚不清楚为什么要使用方法ObjectMapper.转换值(Object fromValue, Class

你可能想要的是ObjectMapper. readValue(字符串内容,类