CXF:当对象通过SOAP发送时,如何排除某些属性? [英] CXF: how to exclude some properties when object sent through SOAP?
问题描述
我使用Apache CXF 2.4.2,当我从数据库向用户返回img时,我想排除一些属性(例如,密码)。我该如何不创建临时类?
I use Apache CXF 2.4.2 and when I'm returnimg some object from the database to user I want to exclude some properties (for instance, password). How I can do that without creating temporary class? Is there annotation for this?
推荐答案
根据@ tomasz-nurkiewicz的注释,我应该使用 @XmlTransient
注释。但是,如文档中所述
As per @tomasz-nurkiewicz comment I should use @XmlTransient
annotation. But as noted in documentation
默认情况下,如果不存在类上的@XmlAccessorType,并且其任何超类都不使用@XmlAccessorType进行注释,则假定该类具有以下默认值:
By default, if @XmlAccessorType on a class is absent, and none of its super classes is annotated with @XmlAccessorType, then the following default on the class is assumed:
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
其中 XmlAccessType.PUBLIC_MEMBER
表示:
每个公共除非使用XmlTransient注释,否则getter / setter对和每个公共字段都将自动绑定到XML。私有,受保护或默认为仅打包访问的字段或getter / setter对仅在由相应的JAXB注释显式注释时才绑定到XML。
Every public getter/setter pair and every public field will be automatically bound to XML, unless annotated by XmlTransient. Fields or getter/setter pairs that are private, protected, or defaulted to package-only access are bound to XML only when they are explicitly annotated by the appropriate JAXB annotations.
所以这就是为什么 @XmlTransient
在私有字段中不起作用的原因例如Tomasz Nurkiewicz。有两种方法可以解决此问题:
So this is why @XmlTransient
for private field doesn't work in example from Tomasz Nurkiewicz. There are two possible ways to fix that:
1)向公共获取者添加注释:
1) Add annotation to public getter:
private String password;
@XmlTransient
public String getPassword() {
return password;
}
2)添加 @XmlAccessorType
进行分类:
@XmlAccessorType(XmlAccessType.FIELD)
public User {
@XmlTransient
private String password;
}
位于:http://old.nabble.com/@XmlTransient-ignored-td7406659.html
这篇关于CXF:当对象通过SOAP发送时,如何排除某些属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!