convert object jpa to json

0

As such, I am developing a web application with spring boot and I can not find a way to return the result of a jpa query in json format using an ajax request. If I create an instance of one of my entities and return it in the controller with @ResponseBody it works perfectly but if I return an ArrayList or that same instance being the result of a query in the repository Spring tool suite hangs.

    
asked by Jose Antonio 17.07.2016 в 17:42
source

1 answer

0

You could use the library JSONObject that comes in primefaces that is very easy to use I leave you an example:

 JSONObject body = new JSONObject();
    body.put("identificador", Integer.parseInt(empleadoAccion.getIdentificador()));
    body.put("accion", "bloquear");
    body.put("url", sesion.getSesion().getRequestUri());
    body.put("ip", sesion.getSesion().getIp())

if you use maven then you can add it to the pom in this way

<dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>5.3</version>
        <type>jar</type>
    </dependency>

Or you can download the library here

    
answered by 13.12.2017 в 22:20