Using Jersey and Jackson to create a REST interface, how do I get List fields to be serialized as a list when there are 0 or 1 elements in them. For example:
@XmlRootElement(name="foo")
public class Foo {
@XmlElement
public List<Bar> getBars() {
return this.bars;
}
}
@Path("foo")
public FooResource {
@GET
public Foo getFoo() {
return theFoo;
}
}
When bars has no elements, the result serializes as null
and when it contains a single element, it serializes as that element, not an array containing a single element. Is there a way to get these to always serialize as an array?
For reference, I'm using Jersey 1.10 and Jackson 1.9.2.