JAXB Annotated class - setting of a variable which is not an element

Posted by sswdeveloper on Stack Overflow See other posts from Stack Overflow or by sswdeveloper
Published on 2010-04-05T20:28:42Z Indexed on 2010/04/05 20:33 UTC
Read the original article Hit count: 214

Filed under:
|

I have a JAXB annotated class say

@XmlRootElement(namespace = "http://www.abc.com/customer")
Class Customer{
@XmlElement(namespace = "http://www.abc.com/customer")
  private String  Name;
  @XmlElement(namespace = "http://www.abc.com/customer")
  private String  Address;
 @XmlTransient
  private HashSet set = new HashSet();

  public String getName(){
    return Name;
  }
  public void  setName(String  name){
    this.Name = name;
    set.add("Name");
  }


  public String getAddress(){
    return Address;
  }
  public void  setAddress(String  address){
    this.Address = address;
    set.add("Address");
  }

  public void getSet(){
return set;
}

I have a XML of the form

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Customer xmlns="http://www.abc.com/customer" >
<Name>Ralph</Name>
<Address>Newton Street</Address>
</Customer>

I use JAXB unmarshalling to get the object representation of the XML input. The values for Name and Address are set correctly. However the value of set gets lost(since it is @XMLTransient it gets ignored)

Is there any way of ensuring that it is still set in the object which has been unmarshalled? Some other annotation which I can use?

© Stack Overflow or respective owner

Related posts about java

Related posts about jaxb