XSD anytype and jaxb

I have an xsd definition (from www.tmforum.org ossj common api v1.5)

<element name="primaryKey" nillable="false">
   <complexType mixed="false">                   
      <complexContent mixed="false">
         <extension base="anyType"/>                   
      </complexContent>
   </complexType>
</element>

and would like to create xml as follows

<ossj-co-v1-5:primaryKey>mykey</ossj-co-v1-5:primaryKey>

The PrimaryKey class generated from xsd using xjc requires that the DOM element be saved in a list (see the generated PrimaryKey class below. "" MyKey "is TextNode here and, since it is not a DOM element, it cannot be added to xjc PrimaryKey class generated. How do I get to the required output?

Here is the PrimaryKey class generated from xsd

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
    "any"
    })
public static class PrimaryKey {

    @XmlAnyElement
    protected List<Element> any;
    @XmlAnyAttribute
    private Map<QName, String> otherAttributes = new HashMap<QName, String>();

    public List<Element> getAny() {
        if (any == null) {
            any = new ArrayList<Element>();
        }
        return this.any;
    }


    public Map<QName, String> getOtherAttributes() {
        return otherAttributes;
    }

}
+3
source share
2 answers

. .

№ 1

, . , "primaryKey" PrimaryKey , .

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "", propOrder = {"any" }) 
public static class PrimaryKey { 

    @XmlValue
    protected String any; 

    @XmlAnyAttribute 
    private Map<QName, String> otherAttributes = new HashMap<QName, String>(); 

    public List<Element> getAny() { 
        if (any == null) { 
            any = new ArrayList<Element>(); 
        } 
        return this.any; 
    } 


    public Map<QName, String> getOtherAttributes() { 
        return otherAttributes; 
    } 

} 

№ 2

, String, , :

@XmlAccessorType(XmlAccessType.FIELD) 
public class Root {

    // @XmlElement is implied
    private String primaryKey;

}
+3

№ 1 getAny() String, List.

№2 . !

OSSJ:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ManagedEntityKey", propOrder = {
    "applicationContext",
    "applicationDN",
    "type",
    "primaryKey"
})
public class ManagedEntityKey {
   @XmlElement(required = true)
   protected String primaryKey;
   //protected ManagedEntityKey.PrimaryKey primaryKey;

, , .

+1

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


All Articles