2015-07-10 14 views
8

Sono in esecuzione di un compito wsimport con le seguenti associazioni di file:Perché JAXB generateElementProperty = false non ha l'effetto desiderato?

<jaxb:bindings version="2.1" 
       xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" > 
    <jaxb:bindings> 
     <jaxb:globalBindings generateElementProperty="false" typesafeEnumMaxMembers="2000" /> 
    </jaxb:bindings> 
</jaxb:bindings> 

Tuttavia, questo si traduce in classi con JAXBElement<String> invece di String come mostrato nella getUserSummaryOrTypeOrLogLevel() sotto

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "ConfigSLMAction", propOrder = { 
    "userSummaryOrTypeOrLogLevel" 
}) 
public class ConfigSLMAction 
    extends ConfigConfigBase 
{ 

    @XmlElementRefs({ 
     @XmlElementRef(name = "UserSummary", type = JAXBElement.class, required = false), 
     @XmlElementRef(name = "LogLevel", type = JAXBElement.class, required = false), 
     @XmlElementRef(name = "Type", type = JAXBElement.class, required = false) 
    }) 
    protected List<JAXBElement<String>> userSummaryOrTypeOrLogLevel; 
    @XmlAttribute(name = "name") 
    protected String name; 
    @XmlAttribute(name = "local") 
    protected Boolean local; 
    @XmlAttribute(name = "intrinsic") 
    protected Boolean intrinsic; 
    @XmlAttribute(name = "read-only") 
    protected Boolean readOnly; 
    @XmlAttribute(name = "external") 
    protected Boolean external; 

    /** 
    * Gets the value of the userSummaryOrTypeOrLogLevel property. 
    * 
    * <p> 
    * This accessor method returns a reference to the live list, 
    * not a snapshot. Therefore any modification you make to the 
    * returned list will be present inside the JAXB object. 
    * This is why there is not a <CODE>set</CODE> method for the userSummaryOrTypeOrLogLevel property. 
    * 
    * <p> 
    * For example, to add a new item, do as follows: 
    * <pre> 
    * getUserSummaryOrTypeOrLogLevel().add(newItem); 
    * </pre> 
    * 
    * 
    * <p> 
    * Objects of the following type(s) are allowed in the list 
    * {@link JAXBElement }{@code <}{@link String }{@code >} 
    * {@link JAXBElement }{@code <}{@link String }{@code >} 
    * {@link JAXBElement }{@code <}{@link String }{@code >} 
    * 
    * 
    */ 
    public List<JAXBElement<String>> getUserSummaryOrTypeOrLogLevel() { 
     if (userSummaryOrTypeOrLogLevel == null) { 
      userSummaryOrTypeOrLogLevel = new ArrayList<JAXBElement<String>>(); 
     } 
     return this.userSummaryOrTypeOrLogLevel; 
    } 
    ... 
    ... 
    ... 
} 

L'entrata in il file xsd generato da questa classe è il seguente:

<xsd:complexType name="ConfigSLMAction"> 
    <xsd:complexContent> 
     <xsd:extension base="tns:ConfigConfigBase"> 
      <xsd:choice maxOccurs="unbounded"> 
       <xsd:element name="UserSummary" minOccurs="0" maxOccurs="1"> 
        <xsd:simpleType> 
         <xsd:union memberTypes="tns:dmString tns:dmEmptyElement" /> 
        </xsd:simpleType> 
       </xsd:element> 
       <xsd:element name="Type" minOccurs="1" maxOccurs="1"> 
        <xsd:simpleType> 
         <xsd:union memberTypes="tns:dmSLMActionType tns:dmEmptyElement" /> 
        </xsd:simpleType> 
       </xsd:element> 
       <xsd:element name="LogLevel" minOccurs="0" maxOccurs="1"> 
        <xsd:simpleType> 
         <xsd:union memberTypes="tns:dmLogLevel tns:dmEmptyElement" /> 
        </xsd:simpleType> 
       </xsd:element> 
      </xsd:choice> 
      <xsd:attributeGroup ref="tns:ConfigAttributes" /> 
     </xsd:extension> 
    </xsd:complexContent> 
</xsd:complexType> 

Qui è il plugin Maven dal mio file pom

<plugin> 
    <groupId>org.jvnet.jax-ws-commons</groupId> 
    <artifactId>jaxws-maven-plugin</artifactId> 
    <version>2.3</version> 
    <executions> 
     <execution> 
      <id>wsimport-from-jdk</id> 
      <phase>generate-sources</phase> 
      <goals> 
       <goal>wsimport</goal> 
      </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <wsdlFiles> 
      <wsdlFile>${basedir}/src/main/resources/wsdl/xml-mgmt.wsdl</wsdlFile> 
     </wsdlFiles> 
     <bindingFiles> 
      <bindingFile>${basedir}/src/main/resources/wsdl/bindings.xml</bindingFile> 
     </bindingFiles> 
     <keep>true</keep> 
     <verbose>true</verbose> 
     <extension>true</extension> 
     <vmArgs> 
      <vmArg>-Djavax.xml.accessExternalDTD=all</vmArg> 
      <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg> 
     </vmArgs> 
    </configuration> 
</plugin> 

Qualcuno può far luce sul motivo per cui questo sta accadendo? Desidero utilizzare String anziché JAXBElement<String> e tutto quello che ho trovato su SO e altrove suggerisce che lo generateElementProperty=false funziona ma non lo è.

+0

ok ho trovato una domanda simile: http://stackoverflow.com/questions/22513736/jaxb-avoid-jaxbelement e il problema è con l'elemento di scelta. – hudi

risposta

8

Il JAXBElement è obbligatoria se c'è un xsd:choice dove possono verificarsi sia foo o bar elementi e sono dello stesso tipo. Una semplice stringa non è sufficiente per contrassegnare quale elemento deve essere sottoposto a marshalling.

JAXBElement è necessaria anche se ci sono elementi nillable="true" e minOccurs="0" o se vi sono due elementi globali con lo stesso nome xsd:complexType.

1

puoi provare un altro plug-in per assicurarti che l'errore sia in JAXB? Nel nostro progetto stiamo usando:

 <plugin> 
      <groupId>org.apache.cxf</groupId> 
      <artifactId>cxf-codegen-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>generate-sources-ais</id> 
        <phase>generate-sources</phase> 
        <configuration> 
         <defaultOptions> 
          <bindingFiles> 
           <bindingFile>${basedir}/src/main/resources/wsdl/binding/bindings.xml</bindingFile> 
          </bindingFiles> 
         </defaultOptions> 
         <sourceRoot>${project.build.directory}/generated-sources/cxf</sourceRoot> 
         <wsdlRoot>${basedir}/src/main/resources/wsdl</wsdlRoot> 
         <includes> 
          <include>**/*.wsdl</include> 
         </includes> 
        </configuration> 
        <goals> 
         <goal>wsdl2java</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

e funziona come ti aspetti

UPDATE:

sei plug-destra è ok. È perché elemento di scelta. Probabilmente duplicato con this

+0

Ottenuto lo stesso output con 'JAXBElement ' ma non è stato possibile utilizzare ' -xjc-Xinheritance' poiché il plug-in ha generato un errore – conorgriffin

+0

ah, mi spiace che tu possa perdere questo argomento. Ne hai bisogno solo quando usi l'ereditarietà in binding.xml e poi hai bisogno di un'altra dipendenza. Aggiornerò xml – hudi

+0

Ho lasciato l'arg out comunque, ho ancora le stesse classi di output di quando ho usato il 'jaxws-maven-plugin' – conorgriffin

Problemi correlati