Java 从生成的源创建XML
我正忙于创建XML文档。xsd正在创建java类,但是发生了一些奇怪的事情。我想要一个这样的XMLJava 从生成的源创建XML,java,xml,maven,Java,Xml,Maven,我正忙于创建XML文档。xsd正在创建java类,但是发生了一些奇怪的事情。我想要一个这样的XML <SystemDocumentationService.GetSystemConfigurationResponse> <SystemConfiguration> <TimeStamp> <Value>2017-10-04T13:30:38</Value> </TimeStamp> &l
<SystemDocumentationService.GetSystemConfigurationResponse>
<SystemConfiguration>
<TimeStamp>
<Value>2017-10-04T13:30:38</Value>
</TimeStamp>
<ServiceStartList>
<ServiceIdentification>
<Service>
<ServiceName>CustomerInformationService</ServiceName>
<IBIS-IP-Version>
<Value>token</Value>
</IBIS-IP-Version>
</Service>
</ServiceIdentification>
</ServiceStartList>
</SystemConfiguration>
</SystemDocumentationService.GetSystemConfigurationResponse>
服务结构是
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ServiceStartListStructure", propOrder = {
"serviceIdentifications"
})
public class ServiceStartListStructure {
@XmlElement(name = "ServiceIdentification", required = true)
protected List<ServiceIdentificationStructure> serviceIdentifications;
public List<ServiceIdentificationStructure> getServiceIdentifications() {
if (serviceIdentifications == null) {
serviceIdentifications = new ArrayList<ServiceIdentificationStructure>();
}
return this.serviceIdentifications;
}
}
好的,我解决了我的问题。有两种解决方案。第一次使用
- @JacksonXmlElementWrapper(useWrapping=false)
XmlMapper mapper = new XmlMapper();
mapper.setDefaultUseWrapper(false);
请为我们提供
服务标识结构
的映射。您要删除包含列表的中间对象;ServiceIdentificationStructure是added@daniu当我添加XmlElementWrapper注释时,我得到CustomerInformationService令牌
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SystemDocumentationService.SystemConfigurationData",
propOrder = {
"timeStamp",
"serviceStartList",
"deviceSpecificationList",
"heartbeatIntervall"
})
public class SystemDocumentationServiceSystemConfigurationData {
@XmlElement(name = "TimeStamp", required = true)
protected IBISIPDateTime timeStamp;
@XmlElement(name = "ServiceStartList", required = true)
protected ServiceStartListStructure serviceStartList;
@XmlElement(name = "DeviceSpecificationList", required = true)
protected DeviceSpecificationListStructure deviceSpecificationList;
@XmlElement(name = "HeartbeatIntervall")
protected IBISIPDouble heartbeatIntervall;
//getter's and setter's
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ServiceStartListStructure", propOrder = {
"serviceIdentifications"
})
public class ServiceStartListStructure {
@XmlElement(name = "ServiceIdentification", required = true)
protected List<ServiceIdentificationStructure> serviceIdentifications;
public List<ServiceIdentificationStructure> getServiceIdentifications() {
if (serviceIdentifications == null) {
serviceIdentifications = new ArrayList<ServiceIdentificationStructure>();
}
return this.serviceIdentifications;
}
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ServiceIdentificationStructure", propOrder = {
"service",
"device"
})
public class ServiceIdentificationStructure {
@XmlElement(name = "Service", required = true)
protected ServiceSpecificationStructure service;
@XmlElement(name = "Device", required = true)
protected DeviceSpecificationStructure device;
/**
* Gets the value of the service property.
*
* @return
* possible object is
* {@link ServiceSpecificationStructure }
*
*/
public ServiceSpecificationStructure getService() {
return service;
}
/**
* Sets the value of the service property.
*
* @param value
* allowed object is
* {@link ServiceSpecificationStructure }
*
*/
public void setService(ServiceSpecificationStructure value) {
this.service = value;
}
/**
* Gets the value of the device property.
*
* @return
* possible object is
* {@link DeviceSpecificationStructure }
*
*/
public DeviceSpecificationStructure getDevice() {
return device;
}
/**
* Sets the value of the device property.
*
* @param value
* allowed object is
* {@link DeviceSpecificationStructure }
*
*/
public void setDevice(DeviceSpecificationStructure value) {
this.device = value;
}
}
XmlMapper mapper = new XmlMapper();
mapper.setDefaultUseWrapper(false);