问题描述
我使用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的注释,我应该使用注释。但是,如文档中所述
As per @tomasz-nurkiewicz comment I should use @XmlTransient
annotation. But as noted in documentation
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
其中 XmlAccessType.PUBLIC_MEMBER
表示:
所以这就是为什么 @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;
}
位于:
这篇关于CXF:当对象通过SOAP发送时,如何排除某些属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!