Search Results

Search found 2 results on 1 pages for 'sswdeveloper'.

Page 1/1 | 1 

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

    - by sswdeveloper
    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?

    Read the article

  • need an empty XML while unmarshalling a JAXB annotated class

    - by sswdeveloper
    I have a JAXB annotated class Customer as follows @XmlRootElement(namespace = "http://www.abc.com/customer") public class Customer{ private String name; private Address address; @XmlTransient private HashSet set = new HashSet<String>(); public String getName(){ return name; } @XmlElement(name = "Name", namespace = "http://www.abc.com/customer" ) public void setName(String name){ this.name = name; set.add("name"); } public String getAddress(){ return address; } @XmlElement(name = "Address", namespace = "http://www.abc.com/customer") public void setAddress(Address address){ this.address = address; set.add("address"); } public HashSet getSet(){ return set; } } I need to return an empty XML representing this to the user, so that he may fill the necesary values in the XML and send a request So what I require is : <Customer> <Name></Name> <Address></Address> </Customer> If i simply create an empty object Customer cust = new Customer() ; marshaller.marshall(cust,sw); all I get is the toplevel element since the other fields of the class are unset. What can I do to get such an empty XML? I tried adding the nillable=true annotation to the elements however, this returns me an XML with the xsi:nil="true" which then causes my unmarshaller to ignore this. How do I achieve this?

    Read the article

1