jaxb2: generate default values by means of jaxb2-default-value plugin.
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 11 Aug 2016 18:05:48 +0000 (20:05 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 11 Aug 2016 18:05:48 +0000 (20:05 +0200)
Wi will use it when having default fields in some XSD.

SOAP/jaxb2/web-services-spring-jaxb2-globalxsds/pom.xml
SOAP/jaxb2/web-services-spring-jaxb2-globalxsds/src/main/resources/schemas/parent.xsd

index 35278a9..b89b410 100644 (file)
                                        <strict>true</strict>
 
                                        <verbose>true</verbose>
+
+                    <!--
+                            By means of this plugin Java objects
+                            will return (as default value) their default values declared in the XSD file.
+                            This feature is not found in the xjc Java tool.
+
+                            It is using the XSD attribute "default" when
+                            trying to find the default value to be returned when no other value
+                            is available in the Java object.
+                    -->
+                    <args>
+                        <arg>-Xdefault-value</arg>
+                    </args>
+                    <plugins>
+                        <plugin>
+                            <groupId>org.jvnet.jaxb2_commons</groupId>
+                            <artifactId>jaxb2-default-value</artifactId>
+                            <version>1.1</version>
+                        </plugin>
+                    </plugins>
                                </configuration>
                        </plugin>
                </plugins>
index fea4a95..4f788d8 100644 (file)
@@ -35,7 +35,7 @@
        <!-- WARNING: I DO NOT KNOW WHY BUT TYPES WORK BETTER WITH JAXB IF THEY END WITH THE Type SUFFIX!!!! :/ -->
        <xsd:complexType name="elementType">
         <xsd:sequence>
-            <xsd:element name="message" type="xsd:string"/>
+            <xsd:element name="message" type="xsd:string" default="This is a default message. Used by jaxb2-default-value."/>
             <xsd:element name="messageArgs" type="xsd:string" minOccurs="0" maxOccurs="100"/>
         </xsd:sequence>
     </xsd:complexType>
@@ -43,7 +43,7 @@
     <xsd:element id="GeneralFault" name="GeneralFault">
        <xsd:complexType>
                <xsd:sequence>
-                       <xsd:element name="technicalError" type="xsd:string" />
+                       <xsd:element name="technicalError" type="xsd:string" default="This is a default error. Used by jaxb2-default-value."/>
                        <xsd:element name="elements" type="elementType" minOccurs="0" maxOccurs="unbounded"/>
                </xsd:sequence>
        </xsd:complexType>