Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide an entity variable from xml message - @XmlTransient not working

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.

like image 919
David031 Avatar asked Sep 04 '13 00:09

David031


1 Answers

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
like image 157
bdoughan Avatar answered Sep 19 '22 11:09

bdoughan