@XmlTransient 用于 javaBean 属性

发布于 2024-12-09 01:09:06 字数 1175 浏览 2 评论 0原文

我感兴趣的是不编组/解编我的 A 对象的主要字段。我在不同的地方添加了 XmlTransient 但它似乎仍然对其进行封送。

有什么想法吗?

这是 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;
    }
}

这是我整理它的方式:

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

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);)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷乱花海 2024-12-16 01:09:06

尝试在您的类上指定 @XmlAccessType(XmlAccessType.FIELD)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文