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

Query related to JaxB Unmarshalling : no setter methods in Unmarshalled java classes  RSS feed

 
aravind kanganar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm trying to unmarshal an xml schema. I used the tool XJCFacade provided under JaxB package com.sun.tools.xjc.

After running the tool the autogenerated classes wont havesetters methods to corresponding properties.

My question is how am I supposed to set properties in respective instances of those autogenereated classes.

Should i add my own setter method or is there any other standard way to do this.

Hope I have made my doubt clear.

Please help...

-aravind
 
R Srini
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. Please post a small sample schema that can be used to duplicate this behaviour.
 
aravind kanganar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi below is PhoneDirectory.xsd which has request for phonenumbers associated with an userId and response giving corresponding phone numbers.

The unmarshalled class corresponding to the response element (PhoneNumberResponse.java) doesn't contailn any setter method. Instead it has one getPhoneNumber() method which return list of phone numbers.


 
R Srini
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aravind. This is the PhoneNumberResponse element

The generated code is:
This is how it works when you have arrays/sequences in the schema. You use getPhoneNumber() to get the list and then use list.add() to add data. For non-sequence items, you should see the regular getters.
 
aravind kanganar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay This solved my problem. Thanks alot Srini!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!