【发布时间】:2017-10-05 18:16:41
【问题描述】:
我正在尝试从 XSD->POJO->JSON 使用区分大小写的 UPS 跟踪 API。我在生成的 JSON 中使用 Jackson 2.6.7。当我应该在下面看到时,我会看到骆驼案例名称:
"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 bean 如下所示:
@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 方法。 -
我之前尝试过,它确实创建了所需的属性,但仍然创建了其他不需要的属性。
标签: java json xsd jersey jackson