Configure JAXB 2.0 generated method names from xsd: choice element

I am trying to figure out how to set up the method name that JAXB 2.1.12 creates. I have an epic XML schema (which is not in my control) and it contains a group with a select element that contains about 200 other elements. Therefore, when I create JAXB classes, the get () method that is created is pretty useless - it ends with something like "getElement1AndElement2AndElement3 ()".

I would like to rename the get () method to be something better, but I cannot figure out exactly how to do this. I know that the tutorial describes setting class names with an element.

I found a really old article ( http://onjava.com/pub/a/onjava/2003/12/10/jaxb.html?page=2 ) that describes attaching the "name" attribute to an element that seems to be I need to do. Unfortunately, I think the article is for version 1.x of JAXB, and the name attribute is no longer valid in the select item with JAXB 2.0.

Does anyone know how I can customize the method name that is generated? Please let me know if examples or any other information will be useful, or if what I am trying to do is not possible.

Thank!

+3
source share
1 answer

I tried with the example provided in the provided link and the following binding.xjb file works:

<jxb:bindings version="1.0"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <jxb:bindings>
      <jxb:bindings schemaLocation="po4.xsd" node="/xs:schema/xs:element[@name='Widgets']//xs:complexType//xs:choice">
            <jxb:property name="Shapes"/>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>

JAXB 2.1.12.

, .

+5

Source: https://habr.com/ru/post/1732035/


All Articles