使用Jackson ObjectMapper将映射转换为POJO会引发异常
我有一个使用Jackson ObjectMapper将映射转换为POJO会引发异常,jackson,objectmapper,Jackson,Objectmapper,我有一个多值map,它表示POST请求的表单参数。我想从这个类转换一个POJO,其中只包含需要进一步处理的字段。我从JacksonObjectMapper中找到了一些建议使用convertValue()的答案 但是,此操作失败,出现以下例外情况: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_A
多值map
,它表示POST请求的表单参数。我想从这个类转换一个POJO,其中只包含需要进一步处理的字段。我从JacksonObjectMapper
中找到了一些建议使用convertValue()
的答案
但是,此操作失败,出现以下例外情况:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token
at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: MyPojo["order_no"])
以下是调试器中输入的外观:
我需要将
字符串
类型替换为ArrayList
,这似乎有效:
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyPojo {
private ArrayList<String> status;
@JsonProperty("order_no")
private ArrayList<String> orderId;
@JsonProperty("tid")
private ArrayList<String> transactionId;
}
@allargsconstuctor
@诺尔格构装师
@吸气剂
@塞特
@JsonIgnoreProperties(ignoreUnknown=true)
公共类MyPojo{
私有数组列表状态;
@JsonProperty(“订单号”)
私有arraylistorderid;
@JsonProperty(“tid”)
私有ArrayList事务ID;
}
您能显示输入吗?添加了调试器的屏幕截图。可能是因为我使用了多值映射
而不是映射
?order\u no
是一个列表而不是字符串
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token
at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: MyPojo["order_no"])
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyPojo {
private ArrayList<String> status;
@JsonProperty("order_no")
private ArrayList<String> orderId;
@JsonProperty("tid")
private ArrayList<String> transactionId;
}