gpt4 book ai didi

java - CXF:如何在通过 SOAP 发送对象时排除某些属性?

转载 作者:搜寻专家 更新时间:2023-10-31 08:18:00 26 4
gpt4 key购买 nike

我使用 Apache CXF 2.4.2,当我从数据库返回一些对象给用户时,我想排除一些属性(例如,密码)。我如何在不创建临时类的情况下做到这一点?这个有注释吗?

最佳答案

根据@tomasz-nurkiewicz 的评论,我应该使用 @XmlTransient注解。但正如文档中所述

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)

XmlAccessType.PUBLIC_MEMBER 意味着:

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 对于私有(private)字段在 Tomasz Nurkiewicz 的示例中不起作用。有两种可能的方法来解决这个问题:

1) 给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

关于java - CXF:如何在通过 SOAP 发送对象时排除某些属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7711978/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com