users@jersey.java.net

[Jersey] Jersey client can't handle an empty response

From: Mike Baranczak <mbaranczak_at_gmail.com>
Date: Thu, 5 Aug 2010 11:28:21 -0400

Paul:

My client code is pretty simple:

    XDictionary xmap =
client.resource(uri).accept(MIME).get(XDictionary.class);

XDictionary is a JAXB-annotated class that extends HashMap<String,
String>.

I thought about using a wrapper class like EntityHolder, but it would
be nice if I didn't have to. Here's the way I see it: on the server
side, I have a resource method that returns null. The Jersey server
produces an HTTP response that encapsulates the null value. However,
the Jersey client throws an exception when it sees this response. The
correct behavior in the above client code would be to set xmap to null.

In other words, the Jersey client should be capable of handling
responses produced by the Jersey server.

-MB


> From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
> Hi Mike, Can you share the client code? If you are defining in a get
> say a list of JAXB beans then the client will never return null, it
> will always expect some content to be returned. You need to express
> the requirements that you may or may not have an entity by wrapping
> the type in an EntityHolder, see: https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/core/provider/EntityHolder.html
> Hth, Paul.