users@jersey.java.net

null in response for empty JAXB bean's list

From: <shaper_at_sibmail.com>
Date: Tue, 20 Jan 2009 17:46:20 +0600 (NOVT)

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.