JAVA -JSON-XML-MAP转换
//定义一个MAP对象,将对象传给后端接口接收
Map a = ["api": '11', ZGUID: "1231",BESKZ: "1231",MATNR: "1231",TXTMI: "1231",ZZYSJ: "1231", format: 'xml']
print WebServiceUtils.invoke2(wsdlUrl, ns, 'StandardPortService', 'StandardPortSoap11', 'skuRequest', a)
public SkuResponse inbound(@RequestPayload SkuRequest request) {
String xml = ObjectMapperFactory.XML.writeValueAsString(request)//将一个java bean转换成一个String xml
Map params = ObjectMapperFactory.INSTANCE.convertValue(request, Map.class)//将一个java bean转换成一个Map
org.json.JSONObject xmljson= XML.toJSONObject(xml)//将一个String XML转换成一个jsonObject
Object xjon = ObjectMapperFactory.JSON.writeValueAsString(request)//将一个java bean转换成一个json,得到的是一个String,虽然这里定义的是Object的类型,实际上得到的还是一个String
//
//Map ttx = ObjectMapperFactory.INSTANCE.convertValue(xjon, Map.class)
Map ttxa = JSON.parse(xjon)//将一个Object对象转换成一个map
SkuRequest ttxw = ObjectMapperFactory.INSTANCE.convertValue(params, SkuRequest.class)//将一个java bean 转换的map转换成一个java bean的对象
// SkuRequest ttxwS = ObjectMapperFactory.INSTANCE.convertValue(xmljson, SkuRequest.class)
//SkuRequest ttxwS1= ObjectMapperFactory.INSTANCE.convertValue(xjon, SkuRequest.class)
SkuRequest ttxwS2 = ObjectMapperFactory.INSTANCE.convertValue(ttxa, SkuRequest.class)//将一个json转换得到的map,转换成一个java bean对象
//String xml=skuXml(request)
ResponseMessage rsp = erpSvc.sendWms(request.api, xml, request.format, request.customerId, params, '')
SkuResponse response = new SkuResponse(code: rsp.code, msg: rsp.msg, data: erpSvc.convertToStr(rsp.data))
return response
}
//将一个String的Json转为Object对象
Object datas= convertToObject(datax,Object.class)
//将对象转为一个List
List<Map> dataList=datas as List
/////////////////////////////////以下是skuRequest的实体类对象
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package com.ittx.edi.erp.standard.domain;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(
name = "",
propOrder = {"api", "zguid", "matnr", "txtmi", "zzysj", "beskz", "volummara", "meins", "bstme", "ausme", "qteunit", "umren", "umrez", "zzthgx", "zzthwl", "ekgrp", "sobsl", "plifz", "webaz", "format", "customerId", "sign"}
)
@XmlRootElement(
name = "skuRequest"
)
public class SkuRequest {
@XmlElement(
required = true
)
protected String api;
@XmlElement(
name = "ZGUID",
required = true
)
protected String zguid;
@XmlElement(
name = "MATNR",
required = true
)
protected String matnr;
@XmlElement(
name = "TXTMI",
required = true
)
protected String txtmi;
@XmlElement(
name = "ZZYSJ",
required = true
)
protected String zzysj;
@XmlElement(
name = "BESKZ",
required = true
)
protected String beskz;
@XmlElement(
name = "VOLUMMARA",
required = true
)
protected String volummara;
@XmlElement(
name = "MEINS",
required = true
)
protected String meins;
@XmlElement(
name = "BSTME",
required = true
)
protected String bstme;
@XmlElement(
name = "AUSME",
required = true
)
protected String ausme;
@XmlElement(
name = "QTEUNIT",
required = true
)
protected String qteunit;
@XmlElement(
name = "UMREN",
required = true
)
protected String umren;
@XmlElement(
name = "UMREZ",
required = true
)
protected String umrez;
@XmlElement(
name = "ZZTHGX",
required = true
)
protected String zzthgx;
@XmlElement(
name = "ZZTHWL",
required = true
)
protected String zzthwl;
@XmlElement(
name = "EKGRP",
required = true
)
protected String ekgrp;
@XmlElement(
name = "SOBSL",
required = true
)
protected String sobsl;
@XmlElement(
name = "PLIFZ",
required = true
)
protected String plifz;
@XmlElement(
name = "WEBAZ",
required = true
)
protected String webaz;
@XmlElement(
required = true
)
protected String format;
@XmlElement(
required = true
)
protected String customerId;
@XmlElement(
required = true
)
protected String sign;
public SkuRequest() {
}
public String getApi() {
return this.api;
}
public void setApi(String value) {
this.api = value;
}
public String getZGUID() {
return this.zguid;
}
public void setZGUID(String value) {
this.zguid = value;
}
public String getMATNR() {
return this.matnr;
}
public void setMATNR(String value) {
this.matnr = value;
}
public String getTXTMI() {
return this.txtmi;
}
public void setTXTMI(String value) {
this.txtmi = value;
}
public String getZZYSJ() {
return this.zzysj;
}
public void setZZYSJ(String value) {
this.zzysj = value;
}
public String getBESKZ() {
return this.beskz;
}
public void setBESKZ(String value) {
this.beskz = value;
}
public String getVOLUMMARA() {
return this.volummara;
}
public void setVOLUMMARA(String value) {
this.volummara = value;
}
public String getMEINS() {
return this.meins;
}
public void setMEINS(String value) {
this.meins = value;
}
public String getBSTME() {
return this.bstme;
}
public void setBSTME(String value) {
this.bstme = value;
}
public String getAUSME() {
return this.ausme;
}
public void setAUSME(String value) {
this.ausme = value;
}
public String getQTEUNIT() {
return this.qteunit;
}
public void setQTEUNIT(String value) {
this.qteunit = value;
}
public String getUMREN() {
return this.umren;
}
public void setUMREN(String value) {
this.umren = value;
}
public String getUMREZ() {
return this.umrez;
}
public void setUMREZ(String value) {
this.umrez = value;
}
public String getZZTHGX() {
return this.zzthgx;
}
public void setZZTHGX(String value) {
this.zzthgx = value;
}
public String getZZTHWL() {
return this.zzthwl;
}
public void setZZTHWL(String value) {
this.zzthwl = value;
}
public String getEKGRP() {
return this.ekgrp;
}
public void setEKGRP(String value) {
this.ekgrp = value;
}
public String getSOBSL() {
return this.sobsl;
}
public void setSOBSL(String value) {
this.sobsl = value;
}
public String getPLIFZ() {
return this.plifz;
}
public void setPLIFZ(String value) {
this.plifz = value;
}
public String getWEBAZ() {
return this.webaz;
}
public void setWEBAZ(String value) {
this.webaz = value;
}
public String getFormat() {
return this.format;
}
public void setFormat(String value) {
this.format = value;
}
public String getCustomerId() {
return this.customerId;
}
public void setCustomerId(String value) {
this.customerId = value;
}
public String getSign() {
return this.sign;
}
public void setSign(String value) {
this.sign = value;
}
}
惜秦皇汉武,略输文采;唐宗宋祖,稍逊风骚。
一代天骄,成吉思汗,只识弯弓射大雕。
俱往矣,数风流人物,还看今朝