{"id":2153,"date":"2023-04-02T13:26:32","date_gmt":"2023-04-02T05:26:32","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=2153"},"modified":"2023-04-05T19:45:47","modified_gmt":"2023-04-05T11:45:47","slug":"jackson-json-deserialization-compatible-with-json-object-and-string","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/04\/02\/jackson-json-deserialization-compatible-with-json-object-and-string\/","title":{"rendered":"Jackson JSON\u53cd\u5e8f\u5217\u5316\u517c\u5bb9JSON\u5bf9\u8c61\u548c\u5b57\u7b26\u4e32"},"content":{"rendered":"<h3>\u6848\u4f8b\u4e00<\/h3>\n<pre><code class=\"language-java\">no String-argument constructor\/factory method to deserialize from String val<\/code><\/pre>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">:Failed\nto read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: \nJSON parse error: Cannot construct instance of `com.example.demo.model.Customer` \n(although at least one Creator exists): no String-argument constructor\/factory\n method to deserialize from String value \n (&#039;{&quot;id&quot;:0,&quot;name&quot;:&quot;Joe&quot;,&quot;city&quot;:&quot;HangZhou&quot;,&quot;contactNum&quot;:123456}&#039;);<\/code><\/pre>\n<p>\u5728spring boot\u524d\u7aef\u8bbf\u95ee\u63a5\u53e3\u7a81\u7136\u51fa\u73b0\u4e0a\u8ff0\u9519\u8bef\uff0c\u540e\u53f0\u63a5\u6536\u53c2\u6570\u63a5\u6536\u5230\u4e86\u5b57\u7b26\u4e32\uff0c\u5bfc\u81f4\u4e0d\u80fd\u53cd\u5e8f\u5217\u5316\u3002\u4f46\u662f\u524d\u7aef\u4ee3\u7801\u770b\u4e0d\u51fa\u4efb\u4f55\u95ee\u9898\u3002<\/p>\n<p>\u89e3\u51b3\u529e\u6cd5\uff1a\u589e\u52a0\u4e00\u4e2a\u6784\u9020\u51fd\u6570\u6765\u624b\u52a8\u8d4b\u503c<\/p>\n<pre><code class=\"language-java\">public SubmitParam(String json) throws IOException {\n    SubmitParam param = new ObjectMapper().readValue(json, SubmitParam.class);\n    this.id = param.getId();\n    this.name = param.getName();\n    this.city = param.getCity();\n    this.contactNum = param.getContactNum();\n}<\/code><\/pre>\n<h3>\u6848\u4f8b\u4e8c<\/h3>\n<pre><code class=\"language-java\">no String-argument constructor\/factory method to deserialize from String value (&#039;null&#039;)<\/code><\/pre>\n<pre><code class=\"language-java\">org.springframework.web.client.RestClientException: \nError while extracting response for type [class cn.appblog.provider.channel.channels.kbank.model.response.QrPayQueryResponse] and content type [application\/json;charset=UTF-8];\nnested exception is org.springframework.http.converter.HttpMessageNotReadableException: \nJSON parse error: Cannot construct instance of `cn.appblog.provider.channel.channels.kbank.model.Metadata` (although at least one Creator exists): no String-argument constructor\/factory method to deserialize from String value (&#039;null&#039;); \nnested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: \nCannot construct instance of `cn.appblog.provider.channel.channels.kbank.model.Metadata` (although at least one Creator exists): no String-argument constructor\/factory method to deserialize from String value (&#039;null&#039;)<\/code><\/pre>\n<pre><code class=\"language-json\">{\n    &quot;id&quot;:&quot;chrg_prod_609e6d56f22797e82d2b7630ac7962766bf&quot;,\n    &quot;object&quot;:&quot;charge&quot;,\n    &quot;created&quot;:&quot;20210331185005000&quot;,\n    &quot;livemode&quot;:true,\n    &quot;amount&quot;:3179,\n    &quot;currency&quot;:&quot;THB&quot;,\n    &quot;description&quot;:&quot;VEMAR I \u0e1c\u0e39\u0e49\u0e19\u0e33\u0e41\u0e1f\u0e0a\u0e31\u0e48\u0e19\u0e43\u0e2b\u0e49\u0e1c\u0e39\u0e49\u0e2b\u0e0d\u0e34\u0e07\u0e22\u0e38\u0e04\u0e43\u0e2b\u0e21\u0e48 \u0e01\u0e23\u0e30\u0e40\u0e1b\u0e4b\u0e32\u0e0a\u0e34\u0e04\u0e17\u0e35\u0e48\u0e44\u0e21\u0e48\u0e0b\u0e49\u0e33\u0e43\u0e04\u0e23 - #20180677492802&quot;,\n    &quot;metadata&quot;:&quot;null&quot;,\n    &quot;source&quot;:{\n        &quot;id&quot;:&quot;qr_prod_4098550e5d3659740f69c974449e85c9bc1&quot;,\n        &quot;object&quot;:&quot;qr&quot;,\n        &quot;brand&quot;:&quot;ThaiQR&quot;,\n        &quot;card_masking&quot;:null,\n        &quot;issuer_bank&quot;:null\n    },\n    &quot;status&quot;:&quot;success&quot;,\n    &quot;order_id&quot;:&quot;order_prod_6094ef376fe68cd8e90aa00810e7a53fce7&quot;,\n    &quot;transaction_state&quot;:&quot;Settled&quot;,\n    &quot;reference_order&quot;:&quot;182021033100920298&quot;,\n    &quot;failure_code&quot;:null,\n    &quot;failure_message&quot;:null\n}<\/code><\/pre>\n<pre><code class=\"language-java\">@Data\n@NoArgsConstructor\npublic class Metadata {\n    private String item;\n    private String qty;\n    private String amount;\n\n    public Metadata(String json) throws IOException {\n        this.item = null;\n        this.qty = null;\n        this.amount = null;\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6848\u4f8b\u4e00 no String-argument constructor\/factory method to de [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[549,74],"class_list":["post-2153","post","type-post","status-publish","format-standard","hentry","category-java-basic","tag-jackson","tag-json"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2153"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2153\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}