I have an Object Ticket which has an element totalNoOfTickets associated with it. I use this object Ticket in many methods of my restful service. However, i only need the element ‘totalNoOfTickets’ for one method only and not others….
For example, in one of my method, i say…
Ticket.setTotalNoOfTickets(7);
I do not use this totalNoOfTickets in other methods. Hence,i do not set it in other methods.
Now in my Ticket.java…I have
public class Ticket
extends ActionType {
@XmlElementWrapper(name = "Tickets")
@XmlElement(name = "Ticket")
protected List<Ticket> tickets;
@XmlElement(name = "TotalNumOfTickets")
protected int totalNumofTickets;
public int getTotalNumofTickets() {
return totalNumofTickets;
}
public void setTotalNumofTickets(int totalNumoftokens) {
this.totalNumofTickets = totalNumoftickets;
}
In method responses, where i set the totalNumoftickets, response contains:
<TotalNumOfTickets>7</TotalNumOfTickets>
But, even in responses, where i do not need totalNumoftickets, reponse contains
<TotalNumOfTickets>0</TotalNumOfTickets>
Is there any way in Jax-B where it would not have
<TotalNumOfTickets>0</TotalNumOfTickets>
in the response of methods, where i do not set totalNumoftickets?…can i use that element optionally
By default a JAXB (JSR-222) implementation will not marshal
nullvalues. You could changetotalNumofTicketsfield/property to anIntegerand have the value null when you don’t want to marshal it.For More Information