问题
I have an entity class:
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)
.
.
.
.
I sent an object of the class via xml in jax-ws web service like so:
<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>
Is it possible to not sent one of the variables such as customerId, which the client shouldn't see? I have added @XmlTransient, but no change.
回答1:
By default public properties are serialized to XML. You will need to mark the corresponding get
method @XmlTransient
. If you wish to a annotate the fields you can add the following to your class @XmlAccessorType(XmlAccessType.FIELD)
.
For More Information
- http://blog.bdoughan.com/2012/04/jaxb-and-unmapped-properties.html
- http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html
回答2:
Tried with @XmlTransient
in different combinations with @XmlAccessorType(XmlAccessType.FIELD)
, on my machine it did not work.
What did work for me, to hide functions, was to annotate each function with @WebMethod(exclude = true)
, to hide it from the wsdl
and thereby exposure to the client.
来源:https://stackoverflow.com/questions/18603517/hide-an-entity-variable-from-xml-message-xmltransient-not-working