how to force jettison to write an array, even if there is only one element in the array? how to force jettison to write an array, even if there is only one element in the array? arrays arrays

how to force jettison to write an array, even if there is only one element in the array?


I found this: https://blogs.oracle.com/japod/entry/missing_brackets_at_json_one

It seems that adding a line to your context resolver to explicitly state that tags is an array is the way to do this; i.e.

props.put(JSONJAXBContext.JSON_ARRAYS, "[\\"tags\\"]");

NB: I'm not familiar with Jettison, so have no personal experience to back this up; only the info on the above blog post.

@Providerpublic class JAXBContextResolver implements ContextResolver<JAXBContext> {    private JAXBContext context;    private Class[] types = {ArrayWrapper.class};    public JAXBContextResolver() throws Exception {        Map props = new HashMap<String, Object>();        props.put(JSONJAXBContext.JSON_NOTATION, "MAPPED");        props.put(JSONJAXBContext.JSON_ROOT_UNWRAPPING, Boolean.TRUE);        props.put(JSONJAXBContext.JSON_ARRAYS, "[\\"tags\\"]"); //STATE WHICH ELEMENT IS AN ARRAY        this.context = new JSONJAXBContext(types, props);    }    public JAXBContext getContext(Class<?> objectType) {        return (types[0].equals(objectType)) ? context : null;    }}