I'm currently with this problem. I have a Date.toString()
. On one side, I want to send this to some other side as a Date
. How to do this?
Here is my code:
public void createEmployee(Employee emp) throws HelicarrierException {
log.debug(LOG_PREFIX + "[SERVICE]-[CREATE-LOG-GOAL] - [GOAL] - [{}]", emp);
HashMap<String, String> map = new HashMap<>();
map.put("nameEmployee", emp.getName());
map.put("admissionalDate", emp.getAdmissionDate().toString());
RestTemplate rt = new RestTemplate();
String url = "http://" + properties.getSktServerEndpoint()
+ ":" + properties.getSktServerPort()
+ properties.getModelEmployee()
+ properties.getCreateEmployee();
log.debug(LOG_PREFIX + "-[URL]-[{}]", url);
log.debug(LOG_PREFIX + "-[PARAMETERS]-[{}]", map);
try {
rt.postForObject(url, emp, Employee.class, map);
}
Note that emp.getAdmissionDate().toString() = Mon Oct 15 00:00:00 BRT 2018
And I'm trying to map this parameter on the other side like this:
@RequestMapping(method = RequestMethod.POST, path = "/create", produces = "application/json")
public ResponseEntity<GenericResponse> create(@RequestParam(value = "nameEmployee") String nameEmployee, @RequestParam(name = "admissionalDate") @DateTimeFormat(pattern="dow mon dd hh:mm:ss zzz yyyy)) Date admissionalDate)
But I always get, Bad Request error. I think the Date
mapping is wrong, but I don't know how to do it right. Anyone know, how to map properly, this string to date?