I have a WebService that returns as the result of the Invokation of the Web-Service a ResponseObject called "CustomerResponse
". When I implement this object "from scratch" everything works fine: My implementation in this case only contains all the needed "Simple Types" like Strings, Integers but NO Object references/associations.
However what I wanted to do is, "reuse" existing Objects. I have in my domain-model a "Customer
" Object that is used in the Application itself. Instead of stupidly more or less cloning the Customer
into the "CustomerReponse" object (by manually typing again all the members/fields), I wanted to base the CutomerResponse
object on the Customer
Object by extension:
class CustomerResponse extends Customer
==> The Problem is that now CustomerResponse
contains some "internal" fields that were inherited from the Customer
Object (like DatabaseID, Security-Stuff) that I do not want to expose via the Web-Service. Furthermore (and thats currently the main problem") Customer
also contains a lot of "object references/associations" to other objects like Address
, Orders
, History
that I do not want to expose via the Webservice either. (It seems that Apache CXF "evaluates" the whole Objectgraph and tries to include them in the ResponseObject...)
==> Is it possible to "Extend" WebService Response Objects based on existing Objects and somehow exclude some "members/fields" of the extended supertyp? (So I want to exclude some members (like the DatabseID) and all of the "object associations" like (Address/Orders/Histroy).. How can I acomplish this, with what annotations and procedures?
Thank you very much!! Jan
Regarding the @XmlTransient annotation, I found out that you need to put it on the getter method of the field you want to hide.
public class InputBean
{
private String fieldShow;
private transient String fieldHide;
public String getFieldShow() {
return fieldShow;
}
public void setFieldShow(String fieldShow) {
this.fieldShow = fieldShow;
}
@XmlTransient
public String getFieldHide() {
return fieldHide;
}
public void setFieldHide(String fieldHide) {
this.fieldHide = fieldHide;
}
}
In the example, "fieldHide" will not be visible on the service xsd.
The @XmlTransient annotation is used to hide members which you do not want shown. You should be able to annotate these members, and they won't be bound. Alternatively, change your @XmlAccessorType to XmlAccessType.NONE and only specifically annotated methods will be bound to XML.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With