users@jaxb.java.net

Re: Issue using XmlMixed, XmlRefrences, XmlRefrence annotations

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Wed, 6 May 2009 09:07:58 +0200

There are several issues, and I don't know which are actually causing your
problem(s) because the code you mailed isn't consistent (to say nothing
about the formatting). Therefore, I can only provide some hints. If you
cannot fix it, you might re-send a complete (compilable) set of classes.

I don't know why you are using XmlMixed. Are you really expecting
content in <CriteriaList>, other than the elements corresponding to
your subclasses? Anyway, that's creating the spurious String element in the
CriteriaListSO's ArrayList.

Make sure that the property names (in @XmlType(propOrder = {...}) are
correct. With IdCriteriaSO it ought to be "ids" (not "Ids").

It's probably better not to use the same tag for the list wrapper as with
the elements (Ids/Ids), but it shouldn't really matter.

You could simply test your stuff by writing a simple marshaller and
unmarshaller. For this, add a file jaxb.index to the package with your
classes, containing:
CriteriaListSO
and create the JAXBContext from this package. If you can do the roundtrip
from Java to XML and back, try again with the web service.

-W

PS: Don't nag - post readable and consistent material.


On Mon, May 4, 2009 at 6:06 PM, Kyle.Bober <kyle.bober_at_gmail.com> wrote:

>
> I am having an issue with @XmlMixed, @XmlRefrences, @XmlRefrence
> annotations...
>
> I have a two classes that extend a base CriteriaSO class. The classes are
> IdCriteriaSO and UserIdCriteriaSO. I also have a List wrapper object
> CriteriaListSO which contains an instance of List<CriteriaSO> objects. I
> annotated the List<CriteriaSO> instance with the @XmlMixed, @XmlReferences
> and @XmlReference annotations. I then created a simple web service that
> takes as a web parameter an instance of CriteriaListSO. The generated WSDL
> looks correct but when I make a request to the web service it doesn't
> populate the List<CriteriaSO> properly.
>
> My issue is every time I send a web service request to the echoCriteria web
> method with some CriteriaSO objects it doesn't set them in the CriteriaList
> object.
> What I do see is one of the CriteriaList - ArrayList element's is being set
> as an object of type java.lang.String. And the contents of the String are
> as
> follows :: "\n" For each CriteriaSO object I add to the SOAP request it
> will
> add an additional \n to the string contents of the String object added tro
> the List.
>
> FYI :: I am using JBoss 4.2.1
>
> Any help or guidance would be appreciated. I have spent a few hours now on
> different annotation configurations trying to figure this out.
>
> The CriteriaSO class ::
>
> @XmlRootElement(name="Criteria")
> @XmlType(propOrder = {"sortType"})
> @XmlSeeAlso({IdCriteriaSO.class})
> public abstract class CriteriaSO {
>
> protected SortType theSortType;
>
> public CriteriaSO() {
> super();
> this.theSortType = KeywordAnalysisSortType.ASCENDING;
> }
>
> @XmlElement(name="SortType", required=true, nillable=false)
> public SortType getSortType() {
> return theSortType;
> }
>
> public void setSortType(SortType aSortType) {
> theSortType = aSortType;
> }
>
> }
>
> I have a two classes that extend the CriteriaSO class ::
>
>
> @XmlRootElement(name="IdCriteria")
> @XmlType(propOrder = {"Ids"})
> public class IdCriteriaSO extends CriteriaSO {
>
> private static final long serialVersionUID = 20090430001L;
>
> private List<Integer> theIds;
>
> public IdCriteriaSO() {
> super(SortType.ASCENDING);
> this.theKeywordAnalysisIds = new ArrayList<Integer>();
> }
>
>
>
> @XmlElementWrapper(name = "Ids", nillable=false, required=true)
> @XmlElement(name = "Id", required = true, nillable = false)
> public List<Integer> getIds() {
> return theIds;
> }
>
> public void setIds(List<Integer> aIds) {
> theIds = aIds;
> }
> }
>
>
> @XmlRootElement(name="UserIdCriteria")
> @XmlType(propOrder = {"userIds"})
> public class UserIdCriteriaSO extends CriteriaSO {
>
> private static final long serialVersionUID = 20090430001L;
>
> private List<Integer> theUserIds;
>
> public UserIdCriteriaSO() {
> super(KeywordAnalysisSortType.ASCENDING);
> this.theUserIds = new ArrayList<Integer>();
> }
>
>
> @XmlElementWrapper(name = "userIds", nillable=false, required=true)
> @XmlElement(name = "userId", required = true, nillable = false)
> public List<Integer> getUserIds() {
> return theUserIds;
> }
>
> public void setUserIds(List<Integer> anUserIds) {
> theUserIds = anUserIds;
> }
> }
>
>
> I then created a List wrapper to contain the CriteriaSO object instances
> like so ::
>
> @XmlRootElement(name="CriteriaList")
> @XmlSeeAlso({IdCriteriaSO.class, UserIdCriteriaSO.class})
> public class CriteriaListSO {
>
> private static final long serialVersionUID = 20090424001L;
>
> private List<CriteriaSO> theCriteria;
>
> public CriteriaListSO() {
> super();
> this.theCriteria = new ArrayList<KeywordAnalysisCriteriaSO>();
> }
>
>
> @XmlMixed
> @XmlElementRefs( {
> @XmlElementRef(name = "IdCriteria", type = IdCriteriaSO.class),
> @XmlElementRef(name = "UserIdCriteria", type = UserIdCriteriaSO.class) })
> public List<CriteriaSO> getCriteria() {
> return theCriteria;
> }
>
> public void setCriteria(List<sCriteriaSO> anCriteria) {
> theCriteria = anCriteria;
> }
> }
>
>
> I have a web service method that takes a CriteriaListSO object as a
> parameter.
>
> @WebService(name="testService", serviceName="testService")
> @SOAPBinding(style=SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL,
> parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
> public class TestService {
>
>
> @WebMethod(operationName = "echoCriteria")
> @WebResult(name = "CriteriaList")
> @RequestWrapper(localName="echoCriteriaRequest")
> @ResponseWrapper(localName="echoCriteriaResponse")
> public CriteriaListSO echoCriteria(@WebParam(name =
> "CriteriaList")CriteriaListSO criteriaListSO) throws RemoteException {
>
> return criteriaListSO;
> }
> }
>
>
> -Kyle
> --
> View this message in context:
> http://www.nabble.com/Issue-using-XmlMixed%2C-XmlRefrences%2C-XmlRefrence-annotations-tp23371452p23371452.html
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>