【问题标题】:com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `response` out of START_ARRAY tokencom.fasterxml.jackson.databind.exc.MismatchedInputException:无法反序列化 START_ARRAY 令牌中的“响应”实例
【发布时间】:2021-11-24 20:32:02
【问题描述】:

当我尝试为此响应执行我的改造调用时,我不断收到此响应:

package retrofit.responses;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
    "id",
    "version",
    "createdDate",
    "modifiedDate",
    "rie",
    "line1",
    "line2",
    "line3",
    "line4",
    "line5",
    "county",
    "postCode",
    "country",
    "primary",
    "accomodationStatus",
    "addressType",
    "effectiveFrom",
    "effectiveTo",
    "secured"
})
@Generated("jsonschema2pojo")
public class ReferralResponse {

@JsonProperty("id")
private Object id;
@JsonProperty("version")
private Integer version;
@JsonProperty("createdDate")
private Object createdDate;
@JsonProperty("modifiedDate")
private Object modifiedDate;
@JsonProperty("rie")
private Boolean rie;
@JsonProperty("line1")
private String line1;
@JsonProperty("line2")
private Object line2;
@JsonProperty("line3")
private Object line3;
@JsonProperty("line4")
private String line4;
@JsonProperty("line5")
private Object line5;
@JsonProperty("county")
private Object county;
@JsonProperty("postCode")
private String postCode;
@JsonProperty("country")
private Object country;
@JsonProperty("primary")
private Boolean primary;
@JsonProperty("accomodationStatus")
private AccomodationStatus accomodationStatus;
@JsonProperty("addressType")
private Object addressType;
@JsonProperty("effectiveFrom")
private Long effectiveFrom;
@JsonProperty("effectiveTo")
private Object effectiveTo;
@JsonProperty("secured")
private Boolean secured;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();

@JsonProperty("id")
public Object getId() {
    return id;
}

@JsonProperty("id")
public void setId(Object id) {
    this.id = id;
}

@JsonProperty("version")
public Integer getVersion() {
    return version;
}

@JsonProperty("version")
public void setVersion(Integer version) {
    this.version = version;
}

@JsonProperty("createdDate")
public Object getCreatedDate() {
    return createdDate;
}

@JsonProperty("createdDate")
public void setCreatedDate(Object createdDate) {
    this.createdDate = createdDate;
}

@JsonProperty("modifiedDate")
public Object getModifiedDate() {
    return modifiedDate;
}

@JsonProperty("modifiedDate")
public void setModifiedDate(Object modifiedDate) {
    this.modifiedDate = modifiedDate;
}

@JsonProperty("rie")
public Boolean getRie() {
    return rie;
}

@JsonProperty("rie")
public void setRie(Boolean rie) {
    this.rie = rie;
}

@JsonProperty("line1")
public String getLine1() {
    return line1;
}

@JsonProperty("line1")
public void setLine1(String line1) {
    this.line1 = line1;
}

@JsonProperty("line2")
public Object getLine2() {
    return line2;
}

@JsonProperty("line2")
public void setLine2(Object line2) {
    this.line2 = line2;
}

@JsonProperty("line3")
public Object getLine3() {
    return line3;
}

@JsonProperty("line3")
public void setLine3(Object line3) {
    this.line3 = line3;
}

@JsonProperty("line4")
public String getLine4() {
    return line4;
}

@JsonProperty("line4")
public void setLine4(String line4) {
    this.line4 = line4;
}

@JsonProperty("line5")
public Object getLine5() {
    return line5;
}

@JsonProperty("line5")
public void setLine5(Object line5) {
    this.line5 = line5;
}

@JsonProperty("county")
public Object getCounty() {
    return county;
}

@JsonProperty("county")
public void setCounty(Object county) {
    this.county = county;
}

@JsonProperty("postCode")
public String getPostCode() {
    return postCode;
}

@JsonProperty("postCode")
public void setPostCode(String postCode) {
    this.postCode = postCode;
}

@JsonProperty("country")
public Object getCountry() {
    return country;
}

@JsonProperty("country")
public void setCountry(Object country) {
    this.country = country;
}

@JsonProperty("primary")
public Boolean getPrimary() {
    return primary;
}

@JsonProperty("primary")
public void setPrimary(Boolean primary) {
    this.primary = primary;
}

@JsonProperty("accomodationStatus")
public AccomodationStatus getAccomodationStatus() {
    return accomodationStatus;
}

@JsonProperty("accomodationStatus")
public void setAccomodationStatus(AccomodationStatus accomodationStatus) {
    this.accomodationStatus = accomodationStatus;
}

@JsonProperty("addressType")
public Object getAddressType() {
    return addressType;
}

@JsonProperty("addressType")
public void setAddressType(Object addressType) {
    this.addressType = addressType;
}

@JsonProperty("effectiveFrom")
public Long getEffectiveFrom() {
    return effectiveFrom;
}

@JsonProperty("effectiveFrom")
public void setEffectiveFrom(Long effectiveFrom) {
    this.effectiveFrom = effectiveFrom;
}

@JsonProperty("effectiveTo")
public Object getEffectiveTo() {
    return effectiveTo;
}

@JsonProperty("effectiveTo")
public void setEffectiveTo(Object effectiveTo) {
    this.effectiveTo = effectiveTo;
}

@JsonProperty("secured")
public Boolean getSecured() {
    return secured;
}

@JsonProperty("secured")
public void setSecured(Boolean secured) {
    this.secured = secured;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
    return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
    this.additionalProperties.put(name, value);
}

}

我正在尝试获取 ID 并在另一个通话中使用它。这是一个我试图将其转换为整数的对象,然后在单独的调用中再次使用它。

    referralResponseResponse = call1.getReferral(token).execute();
    int i = (int) referralResponseResponse.body().getId();
    System.out.println("Int: " + i);

我还应该注意,我使用此数据的 json 非常大,所以我只是使用 jsonpogo 将此信息提取到 java 文件,然后使用适用于我的部分,我不认为我必须设置为返回的 json 的每个部分创建一个 java 类

【问题讨论】:

    标签: java selenium testing jackson retrofit2


    【解决方案1】:

    尝试为您的 POJO 类添加以下注释:

    @JsonIgnoreProperties(ignoreUnknown = true)
    

    【讨论】:

    • 似乎没有任何改变,我应该删除任何注释吗?
    猜你喜欢
    • 1970-01-01
    • 2020-09-07
    • 2017-10-10
    • 2021-01-12
    • 2014-04-16
    • 2020-09-23
    • 1970-01-01
    • 2016-07-30
    • 2015-03-10
    相关资源
    最近更新 更多