Assuming a java class
public class User(){
String name;
Date dateCreated;
}
and a Spring boot controller:
@RequestMapping(value = "getUser", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE))
public User getUser() {
User newUser = new User();
newUser.dateCreated = new Date();
return newUser;
}
If I have a rest API endpoint that returns that User object in JSON format, as above, the dateCreated will be send in timestamp format instead of ISO. Is there any way to make Java return the date in Iso format other than having to specify a new return object that has Date as a String?
One way to do this would be to convert Date to a String and send that but I'm wondering if there's a more convenient way..