Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!