How to consume a JSON... GET and POST

This page shows how to consume a JSON (GET and POST)

How to consume a JSON and populates the data in a table

Using the method: Core.httpGet (String url, String [] mediaType, Class result) ... the script makes a Http Get request and returns a JSON as a String, then it reads the returned JSON and populates the data in the table shown in the figure below

public Response actionIndex() throws IOException, IllegalArgumentException, IllegalAccessException{
Resttest model = new Resttest();
ResttestView view = new ResttestView();
String json = Core.httpGet("", new String[] {}, String.class);
model.setTable_1(new ArrayList<Resttest.Table_1>());
JSONArray aux1 = new JSONArray(json);
for(int i = 0; i < aux1.length(); i ++) {
JSONObject obj = aux1.getJSONObject(i);
Resttest.Table_1 row = new Resttest.Table_1();
row.setSequence("" + obj.getInt("id"));
row.setUserid("" + obj.getInt("userId"));
return this.renderView(view);
Fig. 1

How to consume a JSON/POST

The script below allows you to collect the data (Name, Job) of the form shown in the fig. 2 and then make an HTTP POST, invoking an API ... If the operation is successful, it returns the JSON as a String and prints it in a message INFO.

Fig. 2
public Response actionGuardar() throws IOException, IllegalArgumentException, IllegalAccessException{
Restpost model = new Restpost();
String dados = "{\"name\": \"" + model.getNome() + "\",\"job\": \"" + model.getJob() + "\"}"; response =
new String[] {"application/json; charset=UTF-8"},
if(response.getStatus() == 200 || response.getStatus() == 201) {
String resultPost = response.readEntity(String.class);
Core.setMessageInfo("JSONResult: " + resultPost);
}else {
return this.redirect("mywebapp","Restpost","index", this.queryString());