Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using JAXB to generate java classes based on some XSD schemas. For an element such as:

<xsd:element name="REC_LOC" type="xsd:string" minOccurs="1"/>

jaxb generates the following code:

@XmlElement(name = "REC_LOC", required = true)
protected String recloc;

public String getRECLOC() {
    return recloc;
}

/**
 * Sets the value of the recloc property.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setRECLOC(String value) {
    this.recloc = value;
}

The problem is that we need to use some proprietary XML tools that rely on the naming convention of the getter/setter methods. For example, for the field REC_LOC they expect methods called getRecLoc(String value) and setRecLoc(), instead of getRECLOC().

Is there any way to customise the method names generated by jaxb?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
459 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use the jaxb:property customization to customize the property name.

<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
          xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          version="2.1">

    <bindings schemaLocation="schema.xsd" version="1.0" node="/xs:schema">
        <bindings node="xs:complexType[@name='SOME_TYPE']">
            <bindings node="xs:sequence/xs:element[@name='REC_LOC']">
                <property name="RecLoc"/>
            </bindings>
        </bindings>
    </bindings>
</bindings>

(Not tested.)

See also:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...