Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Newbie JAXBElement Constructor question (using Collections)  RSS feed

 
Chintan B Shah
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,

I am newbie to JAXB Web-services and having tough time creating a JAXBElement constructor.



I am getting following error message at line 3.

1. > expected
JAXBElement<List<Region>> r1=new JAXBElement<List><Region>(q,ArrayList.class<Region.class>,r);
2. illegal start of expression
JAXBElement<List><Region>> r1=new JAXBElement<List><Region>(q,ArrayList.class<Region.class>,r);

So my question is "how to represent a ".class" parameter in JAXBElement constructor which has collections".

I know that it works well for regular data types.
e.g. JAXBElement<String> createdBy=new JAXBElement<String>(new QName(entityNameSpace,"CreatedBy"),String.class,created_by);

I am consuming WSDL file and cant modify it to get rid of JAXB content.

Any help is appreciated.

Pardon my ignorance if answer is really easy.

Thanks
Chintan.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
First of all, what do you want to accomplish?
Second, as far as I have experienced, using Java collection classes in connection to data that is to be serialized to XML is not a good idea. Using arrays is a better approach.
Best wishes!
 
Chintan B Shah
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ivan,

I am actually writing a web-service client. The back-end code (stubs) is auto-generated using METRO 2.0 library.

Now, I am trying to construct the call, wherein I am hitting this issue.

Unfortunately, I am not supposed to change the auto-generated code which is generating Collections instead of Arrays.

This is what Java doc says:

public List<JAXBElement<List<Region>>> getRegions()
Gets the value of the regions property.
This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make to the returned list will be present inside the JAXB object. This is why there is not a set method for the regions property.
For example, to add a new item, do as follows:
getRegions().add(newItem);

Objects of the following type(s) are allowed in the list JAXBElement<List<Region>>


Hope that answers your question.

Regards,
Chintan.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
If the method in the web service which you want to call has this signature:

Then you do not need to make any preparations, since the result that you are supposed to receive is a list containing JAXBElements in which each JAXBElement wraps a list of regions.
You do not need to enclose any parameters of any kind.
Best wishes!
 
Chintan B Shah
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ivan,



You are right.

Sometimes, things are just self-explanatory if you take a look at them closely.

Thanks so much for your help. It works now.

Regards,
Chintan.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!