jaxb2-basics

jaxb2 simplify plugin for xs:choice having same types

空扰寡人 提交于 2020-01-07 05:27:18
问题 I'm trying to use jaxb2 basics simplify plugin for my schema to JAXB conversion. It works fine for the complex types like below. Each element is defined inside the xs:choice has different types ( type1 and type2 ). sample.xsd (complex choice type with different type) <xs:complexType name="doclist"> <xs:sequence> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:annotation> <xs:appinfo> <simplify:as-element-property /> </xs:appinfo> </xs:annotation> <xs:element name="document1" type="type1"

Add toString, hashCode, equals while generating JAXB classes in Java

会有一股神秘感。 提交于 2019-12-18 03:34:16
问题 I'm trying to generate JAXB classes from an XSD file programmatically, using Java. I've used the following code snippet to achieve that: .... import java.io.File; import java.io.IOException; import org.xml.sax.InputSource; import com.sun.codemodel.JCodeModel; import com.sun.tools.xjc.api.S2JJAXBModel; import com.sun.tools.xjc.api.SchemaCompiler; import com.sun.tools.xjc.api.XJC; .... .... public static void generateJaxb(String schemaPath, String outputDirectory, String packageName) throws

Add toString, hashCode, equals while generating JAXB classes in Java

允我心安 提交于 2019-12-18 03:34:09
问题 I'm trying to generate JAXB classes from an XSD file programmatically, using Java. I've used the following code snippet to achieve that: .... import java.io.File; import java.io.IOException; import org.xml.sax.InputSource; import com.sun.codemodel.JCodeModel; import com.sun.tools.xjc.api.S2JJAXBModel; import com.sun.tools.xjc.api.SchemaCompiler; import com.sun.tools.xjc.api.XJC; .... .... public static void generateJaxb(String schemaPath, String outputDirectory, String packageName) throws

How to use jaxb_commons plugins from maven

*爱你&永不变心* 提交于 2019-12-13 14:59:11
问题 I'm trying to use a jaxb plugin to insert a interface into a choice element generating the classes from maven. The problem is that I can't seem to figure out how to do so from maven, the repository isn't clear from the documentation and the only example (bellow) doesn't work, it seems to ignore the plugin (maven reports no error about not finding it) or the plugin doesn't have all the adds-ons currently listed in the project documentation: <plugin> <groupId>org.jvnet.jaxb2.maven2</groupId>

Adding annotations to package-info generated by JAXB

余生长醉 提交于 2019-12-11 12:34:28
问题 I have been using annox to add annotations on my jaxb-generated classes (through bindings files) but I can't find a way to add annotations directly on the package (package-info.java). I've been trying to do something like this in my bindings.xml: <jaxb:schemaBindings> <jaxb:package name="my.package"> <annox:annotate> <annox:annotate annox:class="my.Annotation" /> </annox:annotate> </jaxb:package> </jaxb:schemaBindings> but jaxb complains that annox:annotate is not expected to be there. Is

Validate nested object from complex object using jaxb

不羁的心 提交于 2019-12-06 12:13:18
问题 I have a xml representation of object like OrderList (has list of) Orders and each order has a list of commodities. I want to validate my commodities and if not valid I want to remove them from order. If all commodities are invalid then I remove the order from the orderlist. I have been able to validate Orderlist JAXBContext jaxbContext = JAXBContext.newInstance("com.jaxb"); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(new File

JAXB Simplify plugin still usable?

…衆ロ難τιáo~ 提交于 2019-12-05 23:21:28
问题 I tried the solution of the question here JAXB Simplify plugin vs *.xjb. but it failed with the following exception " compiler was unable to honor this simplify:as-element-property customization. It is attached to a wrong place, or its inconsistent with other bindings. " this is customization binding I used <jaxb:bindings node="//xs:complexType[@name='Op']//xs:choice/xs:element[@name='Time']"> <simplify:as-element-property/> </jaxb:bindings> the jaxb simplify plugin confluence page is not

Validate nested object from complex object using jaxb

假如想象 提交于 2019-12-04 18:09:44
I have a xml representation of object like OrderList (has list of) Orders and each order has a list of commodities. I want to validate my commodities and if not valid I want to remove them from order. If all commodities are invalid then I remove the order from the orderlist. I have been able to validate Orderlist JAXBContext jaxbContext = JAXBContext.newInstance("com.jaxb"); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(new File(XSD)); JAXBSource source = new JAXBSource(jaxbContext, orderList); Validator validator = schema

JAXB Simplify plugin still usable?

核能气质少年 提交于 2019-12-04 05:26:40
I tried the solution of the question here JAXB Simplify plugin vs *.xjb . but it failed with the following exception " compiler was unable to honor this simplify:as-element-property customization. It is attached to a wrong place, or its inconsistent with other bindings. " this is customization binding I used <jaxb:bindings node="//xs:complexType[@name='Op']//xs:choice/xs:element[@name='Time']"> <simplify:as-element-property/> </jaxb:bindings> the jaxb simplify plugin confluence page is not accessible, so has anyone used this plugin and can give an example please? Here is my updated schema

Programmatically use WsImport with JAXB plugins without Maven or ANT?

好久不见. 提交于 2019-12-04 02:59:23
问题 I am using WsImport to generate some Java sources from a remote WSDL file. Note that this is being from inside a regular Scala project i.e. it is not being done in a Maven or Ant build: import com.sun.tools.ws.WsImport def run(wsdlFile: File, destination: File, packageName: String = "generated"): Seq[File] = { sys.props("javax.xml.accessExternalDTD") = "all" sys.props("javax.xml.accessExternalSchema") = "all" val xjcArgs = "" //TODO val args = s"-Xnocompile -XadditionalHeaders $xjcArgs -J