Java 使用 fastjson包转对象属性丢失

tech2022-08-02  153

//主对象

public class WaringAcceptBean {     private HeadBean head;     private Body body;          @JSONField(name="Head")     public HeadBean getHead() {         return head;     }     public void setHead(HeadBean head) {         this.head = head;     }     @JSONField(name="Body")     public Body getBody() {         return body;     }     public void setBody(Body body) {         this.body = body;     }

}

 

实例:

String message="{Head{TradeCode:EMG202,TradeTime:2018-12-11 10:09:02,TradeNo: 47fc76b0-bda3-4a37-8905-acb30cc1878f,BranchCode: 01,HospitalCode: 11,SystemCode: WJZXT,HipKeyNo: 123},Body: {MsgSendOrg: 12313,SystemId: 12313,ID: 2312,PatientId: 3123,VisitId: 123213,ConfirmType: 213123,ConfirmContentType: qweqwe,ConfirmContent: 1222,ConfirmId: 123,ConfirmName: 123,ConfirmTime: 1323,Status: 12313,Memo: 234}";

 WaringAcceptBean stub= JSONObject.parseObject(message, WaringAcceptBean.class);

 

以上可以正常将对象转出,如果将Body.java对象  命名为类似   wariningBodyBean.java  ;有可能会导致转出的   stub对象  中  丢失对象wariningBodyBean元素,整个对象等于Null,具体的原因还未探查,留个标记

 

最新回复(0)