wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes JAXB annotation problem/question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "JAXB annotation problem/question" Watch "JAXB annotation problem/question" New topic

JAXB annotation problem/question

Bob Peterson
Ranch Hand

Joined: Jul 30, 2004
Posts: 47
I'm not sure which forum is better for this question, this one or WebServices, since I'm running into this problem while using Apache CXF. But the core problem is with JAXB annotations.

I'm trying to eventually get my response to be a simple list of items, like so:

And here are my classes

I had to create the OrdMedList class because without it, the service interface was initially returning an array of OrdMeds, but there was no <OrdMedList> tag, even though I had a @WebResult(name="OrdMedList") annotation on that. I read that this was a problem with JAXB, and was recommended to create the OrdMedList class.

So now the problem is that the result xml is

I guess it grabs that 'ordMeds' name from the property of the OrdMedList class. So I tried annotating that with the @XmlElement(name="OrdMed") but that created a JAXB error that said:

Class has 2 properties of the same name "ordMeds"
this problem is related to the following location:
at public java.util.List com.test.services.OrdMedList.getOrdMeds()
at com.test.services.OrdMedList
this problem is related to the following location:
at public java.util.List com.test.services.OrdMedList.ordMeds
at com.test.services.OrdMedList

How can I get the response formatted the way I want? Seems like this is much harder than it should be.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: JAXB annotation problem/question
Similar Threads
Doubt on the JAXB: XML Schema to Java mapping for anonymous complex type.
Rendering XML as a response of @RequestMapping
Need Help With JAXB Unmarshaller - Convert XML Back to Java Bean
jaxb marshalling problem
JAXB annotation error