Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAXB annotation problem/question

 
Bob Peterson
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

IllegalAnnotationExceptions
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.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic