Deserialization error. no String-argument constructor/factory method to deserialize from String

4,477 views
Skip to first unread message

Yuriy Barvenko

unread,
Oct 30, 2018, 10:26:00 PM10/30/18
to jackson-user
I am trying to deserialize following JSON

 
   {
     
"deliverLumpSum": 0.0,
     
"faxQId": "{\"type\":\"TAKEAWAY\",\"data\":{\"orderId\":\"AWSWD-AWSAW\",\"orderKey\":\"DERS34S32SD\"}}"
   
}



with help of following custome 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;
     
}
   
}



in to following Object-Structure

    public class AddInfo {

     
protected double deliverLumpSum;
     
     
@JsonDeserialize( using = OrderIdDeserializer.class)
     
public OrderId orderId;

   
}


   
public class OrderId {

     
private String type;
     
private TakeawayData data;

   
}


   
public class TakeawayData {

     
private String orderId;
     
private String orderKey;


   
}


and i got 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 do i wrong and how can i solve this problem?

thx

Yuriy Barvenko

unread,
Oct 31, 2018, 1:32:00 AM10/31/18
to jackson-user

I just forgot to write, that i use a Lombok framework wit @Data for generate get and set methods 

среда, 31 октября 2018 г., 3:26:00 UTC+1 пользователь Yuriy Barvenko написал:

Tatu Saloranta

unread,
Dec 9, 2018, 2:54:48 PM12/9/18
to jackson-user
I know there are a few challenges with using Lombok, but since I do
not use it myself I don't know exact details.
For what it is worth, some other frameworks (auto-values, immutables)
tend to have less problems as they handle code generation bit
differently from Lombok.

But one thing I would make sure is to use latest Jackson databind
module (2.9.7 if possible) first.
And after that if things still are not working, probably search for
"jackson lombok constructor" or something -- I think there are many
blogposts and SO matches that outline workarounds.

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages