Code: Select all
// rest resource function
public Response getList(long custId, String keyword) {
List list = JPADB.getMyEntities(custId, keyword);
StreamingOutput stream = createStream(list);
CacheControl cc = new CacheControl();
cc.setNoCache(true);
return Response.ok().type(TYPE_JSON).cacheControl(cc).entity(stream).build();
}
// somewhere else reuse an existing rest method
MyEntityRest mrest = new MyEntityRest();
Object retvalObj = mrest.getList(1, "test").getEntity();
ByteArrayOutputStream os = new ByteArrayOutputStream(4*1024);
((StreamingOutput)retvalObj).write(os);
String sData = os.toString("UTF-8");
JsonNode jsonRoot = om.readTree(sData);
JsonNode jsonItem = jsonRoot.path("items").get(0);
System.out.println(String.format("%s %s"
, jsonItem.path("code").asText("")
, jsonItem.path("names").get(0).path("value").asText("")
));