@XmlTransient 用于 javaBean 属性
我感兴趣的是不编组/解编我的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在您的类上指定
@XmlAccessType(XmlAccessType.FIELD)
Try specifying
@XmlAccessType(XmlAccessType.FIELD)
on your class