special0ne
special0ne

Reputation: 6263

@XmlTransient for a javaBean property

I am interested in not marshaling/unmarshaling the principal field of my A object. I have added XmlTransient in different places but it still seem to marshal it.

Any ideas?

Here is class A:

    @XmlRootElement(name = "A")
    public class AImpl implements A, Serializable {

    private String attrName;
    private String attrValue;

    @XmlTransient
    private Object principal;

    public class Adapter extends XmlAdapter<AImpl,A> {
        public A unmarshal(AImpl v) { return v; }
        public AImpl marshal(A v) { return (AImpl)v; }
    }

    public String getAttrName() {
    return attrName;
    }
    public void setAttrName(String s) {
    this.attrName = s;
    }

    public String getAttrValue() {
    return attrValue;
    }

    public void setAttrValue(String s) {
    this.attrValue = s;
    }

    @XmlTransient
    public Object getPrincipal() {
    return principal;
    }

    @XmlTransient
    public void setPrincipal(Object o) {
    this.principal = o;
    }
}

Here is how I marshal it:

JAXBContext context = JAXBContext.newInstance(AImpl.class);
Marshaller m = context.createMarshaller();
m.setProperty(javax.xml.bind.Marshaller.JAXB_FRAGMENT,true);
m.marshal(al sw);)

Upvotes: 2

Views: 2367

Answers (1)

Bozho
Bozho

Reputation: 597106

Try specifying @XmlAccessType(XmlAccessType.FIELD) on your class

Upvotes: 1

Related Questions