users@jersey.java.net

[Jersey] Re: How to get entites (of various type) from ClientResponse

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Thu, 29 Mar 2012 10:10:33 +0200

On 3/29/12 2:54 AM, crc32a wrote:
> Pavel some of us are not in control of the rest api we are consuming(We can't
> create objectClass specific resources). We are forced to consume a URL that
> can return multiple types of objects. For example if you tried a GET
> /some/user operation we could expect a User.class to be returned but if the
> operation fails we could get an Error.class object that describes the error
> that occured.

you should at least have some other clue what you can expect in response
entity (status code, media type, ..).

> How would we multiplex the differen't types of objects comming
> back fro the service? I don't know what you mean by return a wrapper class.
> If you mean by write code on the rest server I can't do that I'm only
> writing the client that will consume the rest service.

you should be able to create JAXB annotated class which will comply with
both User.class and Error.class XML representation. Then you could have
some methods like getType and indicate what is really inside. Or you can
unmarshall it by yourself (using hand-made JAXBContext with User and
Error class, ask only for Object and do instanceof checks).

Anyway, the API you are consuming is not well designed..

Regards,
Pavel

>
>
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/How-to-get-entites-of-various-type-from-ClientResponse-tp6183824p7415979.html
> Sent from the Jersey mailing list archive at Nabble.com.
>