I would file this in JIRA but I'm having login troubles at the minute, I
want to put this here in case I forget because it definitely seems like a
bug, albeit one that only happens in a buggy usecase. The line "for (String
s : stuffs)" below creates an NPE, but the problem is that the response is
sent back with as a 200 and a clipped body.. which is simply "[{". It
stopped generating the response body when the property getter method was
hit.
My resource:
@GET
@ApiOperation(value = "Get stuff")
@Produces(MediaType.APPLICATION_JSON)
public List<TestDO> list(@Context HttpServletResponse response) {
TestDO stuff = new TestDO();
stuff.setId(1);
List<TestDO> things = new ArrayList<>();
things.add(stuff);
return things;
}
My data object:
@XmlRootElement(name = "Test")
@XmlAccessorType(XmlAccessType.FIELD)
@ApiModel(value = "Test", description = "Test object")
public class TestDO {
private int id;
private List<String> stuffs = null;
/**
* Empty constructor, required by JAXB.
*/
public TestDO() {
}
public TestDO(int id, String stuffs) {
this.id = id;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public List<String> getStuffs() {
for (String s : stuffs)
System.out.println(s);
return stuffs;
}
public void setStuffs(List<String> stuffs) {
this.stuffs = null;
}
}
This error is shown in log when this happens:
24-Sep-2019 16:42:53.779 SEVERE [ouc5]
org.apache.cxf.jaxrs.utils.JAXRSUtils.logMessageHandlerProblem Problem with
writing the data, class java.util.ArrayList, ContentType: application/json