2017-10-04 13 views
3

XML文書の作成に忙しいです。 xsdはJavaクラスを作成していますが、奇妙なことが起こっています。あなたは、私はしたくないタグServiceIdentifcationが二回発生した何らかの理由で見ることができるように私が代わりに私はこの生成されたソースからXMLを作成する

<SystemDocumentationService.GetSystemConfigurationResponse> 
<SystemConfiguration> 
    <TimeStamp> 
     <Value>2017-10-04T13:30:38</Value> 
    </TimeStamp> 
    <ServiceStartList> 
     <ServiceIdentification> 
      <ServiceIdentification> 
       <Service> 
        <ServiceName>CustomerInformationService</ServiceName> 
        <IBIS-IP-Version> 
         <Value>token</Value> 
        </IBIS-IP-Version> 
       </Service> 
      </ServiceIdentification> 
     </ServiceIdentification> 
    </ServiceStartList> 
</SystemConfiguration> 
</SystemDocumentationService.GetSystemConfigurationResponse> 

を得るように、この

<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> 

のようなXMLを持っていると思います。

Mavenプラグインとして、私は、生成されたJavaクラスはこの1つ

@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 
} 

あるとServiceStartListStructureは、私がいることで何かを推測

@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; 
} 

} 

あるこの1

<plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>jaxb2-maven-plugin</artifactId> 
      <version>1.5</version> 
      <executions> 
       <execution> 
        <id>ibis_ip</id> 
        <goals> 
         <goal>xjc</goal> 
        </goals> 
        <configuration> 
         <extension>true</extension> 
         <packageName>com.ximedes.giva.core.ibisip</packageName> 
         <schemaDirectory>${project.basedir}/src/main/resources/xsd</schemaDirectory> 
         <staleFile>${project.build.directory}/jaxb2/.ibisStaleFileFlag</staleFile> 
         <clearOutputDir>true</clearOutputDir> 
         <bindingDirectory>${project.basedir}/src/main/resources/xsd</bindingDirectory> 
         <bindingFiles>binding.xjb</bindingFiles> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>build-helper-maven-plugin</artifactId> 
      <version>1.10</version> 
      <executions> 
       <execution> 
        <id>test</id> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>add-source</goal> 
        </goals> 
        <configuration> 
         <sources> 
          <source>${basedir}/target/generated-sources</source> 
         </sources> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

を使用していますmavenプラグインは正しくありませんが、わかりません。

編集:

そして、ここではServiceIdentificationStructure

@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; 
} 

} 
+1

「ServiceIdentificationStructure」のマッピングを提供してください。 –

+0

リストを含む中間オブジェクトを削除します。これはあなたが必要とするものです(https://stackoverflow.com/questions/18247182/remove-intermediate-class-when-generating-code-from-schema) – daniu

+0

XmlElementWrapperアノテーションを追加するとServiceIdentifactionStructureが追加されます – Philipp

答えて

0

大丈夫です、私は私の問題を修正しました。それには2つの解決策があります。

  • @JacksonXmlElementWrapper(useWrapping =偽)

注釈最初の使用。 Javaコードが変更できないxsdから生成されるため、私はその解決策を使用できませんでした。

ただし、2番目の解決策は、XmlMapperでdefaultUseWrapperオプションをfalseに設定することです。

XmlMapper mapper = new XmlMapper(); 
mapper.setDefaultUseWrapper(false); 
関連する問題