我試圖從XSD-> POJO-> JSON中使用UPS區分大小寫的UPS跟蹤API。我使用傑克遜2.6.7在生成的JSON中。我看到駱駝的名字時,我應該看到如下:Jackson在編組時忽略了XmlElement名稱/案例JSON
"TrackRequest": { "InquiryNumber": "1Z12345E6205277936" }
生成的Java bean是註釋,像這樣:
@XmlElement(name = "TrackRequest")
protected TrackRequest trackRequest;
我試過幾個映射功能設置,如USE_WRAPPER_NAME_AS_PROPERTY_NAME和USE_STD_BEAN_NAMING這似乎沒有所需的結果。
我產生JSON像這樣:
ObjectMapper mapper = new ObjectMapper();
String jsonRequest = mapper.writeValueAsString(upsRequest);
的upsRequest豆看起來是這樣的:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"upsSecurity",
"trackRequest"
})
@XmlRootElement(name = "Request")
public class Request {
@XmlElement(name = "UPSSecurity")
protected UPSSecurity upsSecurity;
@XmlElement(name = "TrackRequest")
protected TrackRequest trackRequest;
/**
* Gets the value of the upsSecurity property.
*
* @return
* possible object is
* {@link UPSSecurity }
*
*/
public UPSSecurity getUPSSecurity() {
return upsSecurity;
}
/**
* Sets the value of the upsSecurity property.
*
* @param value
* allowed object is
* {@link UPSSecurity }
*
*/
public void setUPSSecurity(UPSSecurity value) {
this.upsSecurity = value;
}
/**
* Gets the value of the trackRequest property.
*
* @return
* possible object is
* {@link TrackRequest }
*
*/
public TrackRequest getTrackRequest() {
return trackRequest;
}
/**
* Sets the value of the trackRequest property.
*
* @param value
* allowed object is
* {@link TrackRequest }
*
*/
public void setTrackRequest(TrackRequest value) {
this.trackRequest = value;
}
}
根據該文件,我應該得到所需的輸出,除非我丟失東西
您可以隨時嘗試添加JSON註釋,例如, '@JsonProperty( 「TrackRequest」)'。如果它在現場不起作用,請嘗試使用getter方法。 – Andreas
我之前給出了一個嘗試,它確實創建了所需的屬性,但其他不需要的屬性仍然創建。 –