user1205079
user1205079

Reputation: 405

Ignore null Tag during marshiling xml using JAXB

is there an option in JAX ignore null value of element from marshaling , so in case i have java object customer and the address is null , during marshaling how can i write the xml with out the address tag (i don;t want to use EclipseLink JAXB (MOXy) )

Code Example:

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="Customer")
public class Customer
{
    @XmlElement(name = "name")  
    String name = null;
    @XmlElement(name = "address")   
    String address = null;

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getAddress()
    {
        return address;
    }

    public void setAddress(String address)
    {
        this.address = address;
    }


}   

in case address is null i expect not to have the address tag in the xml.

Thanks

Upvotes: 0

Views: 3297

Answers (1)

skaffman
skaffman

Reputation: 403481

in case address is null i expect not to have the address tag in the xml

This happens by default.

Upvotes: 1

Related Questions