I am working for the first time with RestFul in an application, currently all the connection was done through a class, called "Connection" that opened the database to make use of the corresponding tables ( pedido
, estado
, franquicia
, local
, carta
).
Now I have been asked to use RestFul to do this, for this I have been guided by the following tutorial:
Creating RESTful Web Services in NetBeans 7 : Part 1
Using RESTful Web Services to Implement CRUD Operations in NetBeans 7: Part 2 <-- I am here
Developing an Ajax Client for RESTful Web Services in NetBeans 7 : Part 3
I have tried with the information of the Table Pedido
, so that it returns the number of existing rows in the database, to verify the correct operation of RestFul
//Método para contar pedidos
public static String contarPedidos(){
String totalPedidos;
totalPedidos = "0";
totalPedidos = pedidoRest.countREST();
return totalPedidos;
}
Which is seen correctly in the view
The problem has arisen when I want to return a complete list of the existing data in the table Estado
to fill aJComboBox
public static void prueba(){
EstadoREST estadoRest = new EstadoREST();
ClientResponse respuesta = estadoRest.findAll(ClientResponse.class);
GenericType<List<Estado>> genericType = new GenericType<List<Estado>>() {};
List<Estado> data = new ArrayList<Estado> ();
data=(respuesta.getEntity(genericType)); //<--Aquí se genera el error
}
According to the tutorial that I am following, that is what I should do, but on that line I get the following error:
I have followed all the steps in the tutorial, what am I doing wrong?
I downloaded all jar
of Jersey here --> JAX-RS 2.1 / Jersey 2.26+
Answering my own question in case someone else went through the same thing:
Looking for more information about it, I realized that the method that creates the RestFul by default when adding it to the project
estadoRest.findAll
can return the information inXML
orJSON
in my case I only wanted it to return a Json, of the JsonArray type (in the case of listing States):For the above:
This was my code:
Beyond the problem where it was being generated, it was that in my case the method I was trying to call is built like this:
And when I wanted it to return the information in Json, I was passing the parameter
responseType
incorrectly, it must be more or less as follows:Summary: My problem was that, in my case, I needed the information to be returned in the format
Json
, but the tutorial showed the case that I wanted to do it withXML
, I was simply sending a parameter in the wrong way, I was sending the methodfindAll
aClientResponse.class
as a parameter, when it should beJsonArray.class
.