Holen Sie sich Jackson JsonNode von Jakarta.Streamingoutput EntityJava

Java-Forum
Anonymous
 Holen Sie sich Jackson JsonNode von Jakarta.Streamingoutput Entity

Post by Anonymous »

Ich habe eine REST -Ressourcenmethode, die eine jakarta.ws.rs.core.streamingoutput Entität zurückgibt. Diese Klasse bietet einen überzeugenden progressiven StreamingOutput. Ich habe diesen Testcode erstellt und er funktioniert einwandfrei. Oder ein anderer Trick, ohne zuerst eine temporäre String SData | zu erstellen os.tobytearray () bytes variable?

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("")
));

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post