Pretty straightforward question. I am using Jersey to build a REST system. If I have a class with a value that I need to use during processing but don’t want sent as part of the XML or JSON output when the class is marshaled, is there a way to ignore it? Something like:
@XmlRootElement(name="example")
class Example {
private int a;
private String b;
private Object c;
@XmlElement(ignore=true)
public int getA() { return a; }
@XmlElement
public String getB() { return b; }
@Ignore
public Object getC() { return c; }
... //setters, constructors, etc.
}
I would hope that something like the ignore=true over getA() or the @Ignore over getC() would work, but i can find no documentation.
There are couple options depending on how many fields/properties you want to be ignored.
Option #1 –
@XmlTransientIf you want less than half of the properties to be ignored then I would recommend annotating them with
@XmlTransient. This will exclude them from the XML mapping.Option #2 –
@XmlAccessorType(XmlAccessType.NONE)If you want more than half of the properties ignored I would recommend using the
@XmlAccessorTypeannotation at the type level to setXmlAccessType.NONE. This will cause only annotated properties to be mapped to XML.For More Information