2017-10-04 1 views
3

XML 문서 작성에 많은 시간을 할애하고 있습니다. xsd가 자바 클래스를 생성하지만 이상한 일이 발생합니다. 당신은 내가 원하지 않는 태그 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을 가지고 싶습니다.

으로 받는다는 플러그인 내가이 일

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

을 사용하고 생성 된 자바 클래스는이 일

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

} 

내가 가진 무언가를 생각하다 메이븐 플러그인은 정확하지 않지만 확실하지 않습니다.

편집 : 여기

그리고는 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 주석 i를 추가하면 ServiceIdentifactionStructure가 – Philipp

답변

0

난 내 문제를 해결 괜찮습니다. 두 가지 해결책이 있습니다. 처음 사용

  • @JacksonXmlElementWrapper (= 거짓 useWrapping)

주석. 내 Java 코드는 xsd에서 생성 할 수 없기 때문에이 솔루션을 사용할 수 없습니다.

그러나 두 번째 해결 방법은 XmlMapper에서 defaultUseWrapper 옵션을 false로 설정하는 것입니다.

XmlMapper mapper = new XmlMapper(); 
mapper.setDefaultUseWrapper(false); 
관련 문제