I have an entity class with a custom type field among other fields
@Entity
@Table(name = "something")
public class Test {
@Id
private Integer id;
private <SomethingHere> customTypeObject;
// Other fields, getters, and setters not shown
}
Using that class I am generating a json representation of the data using repository.findAll()
@Controller
public class TestController {
@AutoWired
private TestRepository repo
@GetMapping("/test")
private List<Test> test() {
return repo.findAll();
}
}
The JSON response to the user is intended to display the fields within the custom type in JSON format.
If I label the customTypeObject as a String, the reponse is something like below
[{id: 1, customTypeObject: "(1,2)"}]
Whereas I would prefer a response like
[{id: 1, customTypeObject: { A: 1, B: 2 }}]
I realize I could do this by creating another entity class for the custom type where I manually type out the fields but I plan on increasing the number of fields in the custom type frequently during the development process so I would prefer if the program would keep track of the fields for me.
Is there any way this could be accomplished?