Estoy tratando de pasar algunos objetos del backend de Java al frontend de JavaScript de la siguiente manera:
Controlador de peso:
String jsonString = new JSONObject() .put("weightEntry", weightEntry).toString(); model.addAttribute("weightEntry", jsonString);usando la siguiente biblioteca para crear un 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>Encontré esto en stackoverflow que está desactualizado (parece) Cómo acceder al atributo del modelo en Javascript