Friday, February 3, 2012

JAXB : @XmlSeeAlso, @XmlAnyElement

These two annotations are used in case of generalization in inheritance. The object of parent class can contain object of any child class.

Example is as below:

//@XmlRootElement(name = "WebServiceMethod")
@XmlRootElement(namespace = "pkg")
@XmlAccessorType(XmlAccessType.FIELD)
//If you want you can define the order in which the fields are written
//Optional
@XmlType(propOrder = { "webServiceMethodName", "webServiceMethodParams" })
@XmlSeeAlso({WebServiceMethodParamComposite.class, WebServiceMethodParamLeaf.class})
public class WebServiceMethod {
String webServiceMethodName;

// XmLElementWrapper generates a wrapper element around XML representation
//@XmlElementWrapper(name = "webServiceMethodParams")
// XmlElement sets the name of the entities
//@XmlElement(name = "WebServiceMethodParam")
//@XmlElement(name = "WebServiceMethodParam")

@XmlAnyElement
ArrayList<WebServiceMethodParamComponent> webServiceMethodParams;

    public WebServiceMethod()
    {       
    }

    public void setWebServiceMethodName(String name)
    {   
        webServiceMethodName = name;
    }

    public String getWebServiceMethodName()
    {   
        return webServiceMethodName;
    }

    public void setWebServiceMethodParam(ArrayList<WebServiceMethodParamComponent> paramList)
    {   
            webServiceMethodParams = paramList;
    }
   
    public ArrayList<WebServiceMethodParamComponent> getWebServiceMethodParam()
    {   
            return webServiceMethodParams;
    }

}

No comments:

Post a Comment