从xml消息隐藏实体变量 - @XmlTransient不起作用

Dav*_*031 7 java xml web-services jaxb xmltransient

我有一个实体类:

public class Customer implements Serializable {
private static final long serialVersionUID = 1L;

@XmlTransient
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "CUSTOMER_ID")
private Integer customerId;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 30)
@Column(name = "NAME")
private String name;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 30)
@Column(name = "ADDRESSLINE1")
private String addressline1;
@Basic(optional = false)
.
.
.
.
Run Code Online (Sandbox Code Playgroud)

我在jax-ws web服务中通过xml发送了类的对象,如下所示:

<addressline1>xx</addressline1><addressline2>xx</addressline2><city>xx</city><country>xx</country><creditLimit>xx</creditLimit><customerId>xx</customerId><email>xx</email><name>xx</name><owner>xx</owner><phone>xx</phone><province>xx</province><zip>xx</zip>
Run Code Online (Sandbox Code Playgroud)

是否有可能不发送其中一个变量,例如customerId,客户端应该看不到?我添加了@XmlTransient,但没有变化.

bdo*_*han 19

默认情况下,公共属性被序列化为XML.您需要标记相应的get方法@XmlTransient.如果您希望对字段进行注释,可以将以下内容添加到您的课程中@XmlAccessorType(XmlAccessType.FIELD).

欲获得更多信息