簡體   English   中英

如何解析對單個JAVA對象的JSON響應

[英]How to parse JSON response to a single JAVA Object

我試圖解析對單個JAVAJSON響應,該JSON響應包含在另一個JSON數組和簡單字段中。

但是,在嘗試中我可以得到以下結果。

13:07:25,769 INFO  [biz.example.ClentManager] (default task-106) Start findBasicAccountInformation intigartion................................
13:07:25,769 INFO  [biz.example.ClentManager] (default task-106) Account No................................200300008212
13:07:25,831 INFO  [biz.example.ClentManager] (default task-106) Response : Response{protocol=http/1.1, code=200, message=OK, url=http://192.168.13.40:8092/v2/accounts/200300008212}
13:07:25,832 INFO  [biz.example.ClentManager] (default task-106) satatus======================>>>OK
13:07:25,832 INFO  [biz.example.ClentManager] (default task-106) statusCode======================>>>200
13:07:25,832 INFO  [biz.example.ClentManager] (default task-106) Start : outputJSONObjects
13:07:25,832 INFO  [biz.example.ClentManager] (default task-106) jsout : {"StatusCode":200,"TraceId":"89C8F03DC3D946A89F43AE94E0B151A0","Status":"SUCCESS","ErrorList":[],"Result":{"CustomFields":[],"AccountNumber":"200300008212","BranchId":"003","Name":"SAHAN MADURANGA","ShortName":"GHJJKGDJ","CustomerId":"358106","SchemeCode":"SA000","SchemeType":"SBA","Currency":"LKR","Ownership":"E","ChargeLevelCode":"GENRL","CloseFlag":"N","DormantStatus":"A","FrezeCode":" ","JointStatus":"M","ModeOfOpertionalCode":null,"CustomerRelationCode":" ","MinorStatus":"N","TransactionStatus":"T","OpenDate":"2011-12-17T00:00:00"}}
13:07:33,793 ERROR [biz.example.ClentManager] (default task-106) com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "StatusCode" (class biz.spsolutions.edgevantage.workflow.dao.PABCIntegration.ResultBasicAccountInformationDao), not marked as ignorable (5 known properties: "traceId", "status", "result", "errorList", "statusCode"])
 at [Source: N/A; line: -1, column: -1] (through reference chain: biz.spsolutions.edgevantage.workflow.dao.PABCIntegration.ResultBasicAccountInformationDao["StatusCode"])
13:10:01,933 WARNING [com.hazelcast.spi.impl.operationservice.impl.InvocationMonitor] (hz._hzInstance_1_dev.InvocationMonitorThread) [IP]:5701 [dev] [3.8.1] MonitorInvocationsTask delayed 147145 ms
13:10:01,933 WARNING [com.hazelcast.spi.impl.operationservice.impl.InvocationMonitor] (hz._hzInstance_1_dev.InvocationMonitorThread) [IP]:5701 [dev] [3.8.1] BroadcastOperationControlTask delayed 145689 ms
13:10:02,021 INFO  [biz.example.ClentManager] (default task-106) End findBasicAccountInformation intigartion................................

你有什么主意嗎 ?

我認為這可以總結出以下錯誤:-com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:無法識別的字段“ StatusCode ”(類biz.spsolutions.edgevantage.workflow.dao.PABCIntegration.ResultBasicAccountInformationDao),未標記為可忽略(5個已知)屬性:“ traceId”,“狀態”,“結果”,“ errorList”,“ statusCode ”])

字段名稱似乎不匹配,一個以大寫S開頭,另一個以小寫S開頭。 請嘗試更改它。

您可以使用以下方法:

@Data
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Builder
public class MyDTO implements Serializable {

    @JsonProperty("id")
    private Long id;


    @JsonProperty("tax_id")
    private Long taxId;

    @JsonProperty("thumbnail")
    private String thumbnail;

    @JsonProperty("short_description")
    private Map<String,Object> shortDescription;

    public static MyDTO buildCatalogProductDTO(MyDomain md) {
    return MyDTO.builder()
            .id(md.getId())
            .taxId(catalogProduct.getTaxId())
            .shortDescription(SerializationUtil.parseJson(md.getShortDescription()))
            .build();
    }

其中SerializationUtil.parseJson在內部使用Gson庫進行轉換。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM