Json 错误com.fasterxml.jackson.databind.exc.MismatchedInputException:Cannot construct instance of

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/qq_40646143/article/details/88116271
在把json数据转换成对象的时候出现这个错误

 

Error Log

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `实体对象` (although at least one Creator exists): no String-argument constructor/factory method to
 deserialize from String value ('{ "responses": { "logisticProviderID": "TTKD", "responseItems": { "response":{ "success": "true" } } } }')
 at [Source: (byte[])
""{ \"responses\": { \"logisticProviderID\": \"TTKD\", \"responseItems\": { \"response\": { \"success\": \"true\" } } } }""; line: 1, column: 1]

 

Solution is as follows

  1. For example, get data json, with escape characters required to remove the escape character, the following is json string bs
    StringEscapeUtils.unescapeJava(new String(bs, Charset.forName("utf-8")))
  2. If the data string is json get out of a plurality s1 ''   needs to be removed, use the following method
    byte[] bytes = s1.substring(1, s1.length() - 1).getBytes();

Guess you like

Origin blog.csdn.net/qq_40646143/article/details/88116271