JAX-WS: How to Exclude a "member/field" in a Response Object (WS Response) that is inherited?
Asked Answered
E

3

9

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

Emblazonment answered 14/11, 2009 at 13:45 Comment(0)
S
7

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.

Scramble answered 18/11, 2009 at 13:46 Comment(1)
Hello KT, thank you very much for your answer. Well I actually tried @XMLTransient but it didnot work somehow. (Apache CXF nevertheless seemed to at least "crawl" the objectgraph on loading the Webservice and threw some exceptions (as My objectgraph has some identically named inner static Enums...). I will try again and will trry your XmlAccessType.NONE. Tanks!Emblazonment
N
11

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.

Newbill answered 29/1, 2013 at 13:40 Comment(3)
Good spot. You need both transient for your field and @XmlTransient for the getter.Minyan
Worked for me without transientAcrefoot
Not working for boolean types. However if you annotate your boolean field it works.Jewess
S
7

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.

Scramble answered 18/11, 2009 at 13:46 Comment(1)
Hello KT, thank you very much for your answer. Well I actually tried @XMLTransient but it didnot work somehow. (Apache CXF nevertheless seemed to at least "crawl" the objectgraph on loading the Webservice and threw some exceptions (as My objectgraph has some identically named inner static Enums...). I will try again and will trry your XmlAccessType.NONE. Tanks!Emblazonment
S
-10

C# solves this problem with partial classes. I don't know how to do it with jax-ws.

Software answered 19/11, 2009 at 23:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.