I have a small Java Springboot backend and a mySQL database. The data class for the objects to be saved in the database looks as follows:
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
private String category;
private LocalDate expirationDate;
// getters, setters ...
The GET method within the controller class looks like this:
@GetMapping("/products")
public ResponseEntity<Iterable<Product>> getProducts() {
return ResponseEntity.ok(productRepository.findAll());
}
Now the json I get back when posting a GET-request formats the expirationDate property as int[], like this:
"expirationDate": [
2023,
1,
22
]
How do I manage to format this while creating the json for it to look like yyyy-mm-dd, as this is the format I also use to POST it. Also, as I'm writing my frontend in Blazor (C#), I need a format that gets easily translated into a DateOnly property in the C# data class.