Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

219
Vistas
What's the best practice for manipulating API response from Java using JavaScript?

I'm using Java Spring Boot for the backend, and Thymeleaf for the frontend. I'm using an API to retrieve and display thousands of images. What I am getting as a response is one JSON object that has thousands of subobjects that each has a link to the image.

I would like to send this big JSON object to the frontend. I'm trying to make an image slider. When I click the '>' button, the next image would appear. '<' button would show the previous image.

This is how I am sending an API response to the frontend. 'model' is an instance of ModelMap.

model.put("apiResponse", apiResponse);

apiResponse object is now accessible from the frontend HTML file. However, I'm not sure how I could manipulate this with JavaScript. Is it that all Java objects can't be handled using JavaScript directly?

In that case, is the best practice to use some kind of library to convert Java objects to JSON? I was wondering if I should do it because it sounds a bit weird:

  1. Originally, the API sends a JSON object.
  2. Java converts it to a Java model using List.
  3. Then Java server sends it to the frontend.
  4. In order to manipulate that using JavaScript, use the JS library to convert it back to JSON.

Isn't it weird that original data is JSON but I have to go through so many steps to make it back to the JSON? Is this really how things work? If not, what's a better way of doing things?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I solved this issue by using Thymeleaf Script Inlining, as suggested by its official documentation.

<script th:inline="javascript">
/*<![CDATA[*/
    var apiResponse = /*[[${apiResponse}]]*/ 'apiResponse';
/*]]>*/
</script>

After that, I was able to access the apiResponse variable in the external js file as well.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda