I have a MultivaluedMap<String, String>
which represents the form parameters of a POST request. I'd like to convert a POJO from this class with only those fields I need for further processing. I found some answers which suggest using convertValue()
from the Jackson ObjectMapper
.
Convert a Map<String, String> to a POJO
public void process(MultivaluedMap<String, String> formParams) {
ObjectMapper objectMapper = new ObjectMapper();
final MyPojo myPojo = objectMapper.convertValue(formParams,MyPojo.class);
}
POJO
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyPojo {
private String status;
@JsonProperty("order_no")
private String orderId;
@JsonProperty("tid")
private String transactionId;
}
However this fails with the following exception:
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"])
This is how the input looks like in the debugger: