Hal*_*lex 1 java json xsd jersey jackson
我正在尝试从XSD-> POJO-> JSON转到要区分大小写的UPS跟踪API。我在生成的JSON中使用Jackson 2.6.7。当我在下面看到时,我看到了骆驼箱的名称:
"TrackRequest": {
"InquiryNumber": "1Z12345E6205277936"
}
生成的Java bean的注释如下:
@XmlElement(name = "TrackRequest")
protected TrackRequest trackRequest;
Run Code Online (Sandbox Code Playgroud)
我尝试了一些映射功能设置,例如USE_WRAPPER_NAME_AS_PROPERTY_NAME和USE_STD_BEAN_NAMING,它们似乎并没有达到预期的效果。
我正在生成JSON,如下所示:
ObjectMapper mapper = new ObjectMapper();
String jsonRequest = mapper.writeValueAsString(upsRequest);
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
根据文档,除非缺少某些内容,否则我应该会获得所需的输出
默认情况下不支持JAXB批注。您需要添加jackson-module-jaxb-annotations模块,然后在中注册该模块ObjectMapper。
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JaxbAnnotationModule());
Run Code Online (Sandbox Code Playgroud)