users@jersey.java.net

Re: [Jersey] null in response for empty JAXB bean's list

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 20 Jan 2009 13:14:43 +0100

What is the output from the Tomcat log?

When you say "null" do you mean? a 204 response a 500 response?

Paul.

On Jan 20, 2009, at 12:46 PM, shaper_at_sibmail.com wrote:

> Hi all,
>
> json-from-jaxb sample was modified again from the
> jersey-samples-1.0.1-project.zip as shown below (Apache Tomcat servlet
> container is used for deployment):
>
> Modified resolver:
>
> @Provider
> public final class JAXBContextResolver implements
> ContextResolver<JAXBContext> {
>
> private final JAXBContext context;
>
> private final Set<Class<?>> types;
>
> private final Class<?>[] cTypes = {Flights.class,
> FlightType.class};
>
> public JAXBContextResolver() throws Exception {
> Map<String, Object> props = new HashMap<String, Object>();
> props.put(JSONJAXBContext.JSON_NOTATION,
> JSONJAXBContext.JSONNotation.MAPPED);
> props.put(JSONJAXBContext.JSON_ROOT_UNWRAPPING, Boolean.TRUE);
> props.put(JSONJAXBContext.JSON_NON_STRINGS, new
> HashSet<String>(1){{add("number");}});
> this.types = new HashSet<Class<?>>(Arrays.asList(cTypes));
> this.context = new JSONJAXBContext(cTypes, props);
> }
>
> public JAXBContext getContext(Class<?> objectType) {
> return (types.contains(objectType)) ? context : null;
> }
>
> }
>
> Modified resource:
>
> @Path(value = "/flights")
> public class FlightList {
>
> private Flights myFlights;
> public FlightList() {
> myFlights = new Flights();
> }
>
> @GET
> @Produces("application/json")
> public synchronized Flights getFlightList() {
> return myFlights;
> }
> ...
> }
>
>
> Expected to be the following content in response: {"flights": []}
>
> But we have got: null
>
> Could you assist to resolve the issue?
>
> Thank in advance,
>
> Dmitry Sh.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>