I am trying to deserialize the following JSON
{
"deliverLumpSum": 0.0,
"faxQId": "{\"type\":\"TAKEAWAY\",\"data\":{\"orderId\":\"AWSWD-AWSAW\",\"orderKey\":\"DERS34S32SD\"}}"
}
With help of the following custom deserializer
public class OrderIdDeserializer extends JsonDeserializer<OrderId> {
@Override
public OrderId deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
OrderId orderId = jsonParser.readValueAs(OrderId.class);
return orderId;
}
}
into the following object-structure
@Data
public class AddInfo {
protected double deliverLumpSum;
@JsonDeserialize( using = OrderIdDeserializer.class)
public OrderId orderId;
}
@Data
public class OrderId {
private String type;
private TakeawayData data;
}
@Data
public class TakeawayData {
private String orderId;
private String orderKey;
}
I get the following error
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of
OrderId
(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('{"type":"TAKEAWAY","data":{"orderId":"AWSWD-AWSAW","orderKey":"DERS34S32SD"}}')
What am I doing wrong and how can I solve this problem?