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

164
Views
Send object from Java backend to JavaScript frontend via model

I am trying to pass some objects from Java backend to the JavaScript frontend as following:

WeightController:

String jsonString = new JSONObject()
   .put("weightEntry", weightEntry).toString();

model.addAttribute("weightEntry", jsonString);

using the following library to create a json:

<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20220320</version>
</dependency> 
@Entity
@Table(name = "WeightEntry")
public class WeightEntry {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @ManyToOne()
    private User user;

    @OneToMany(mappedBy = "weightEntry")
    private Set<Image> imageSet = new HashSet<>();

    private double weight;
    private Date date;

    public WeightEntry() {}
}
<script>
    var obj = eval('('+'${weightEntry}'+')'); //this is not working
    var obj2 = [[${weightEntry}]] //this shows blank??
</script>

I found this on stackoverflow which is outdated (it seems) How to access model attribute in Javascript

about 4 years ago · Juan Pablo Isaza
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!