In a spring rest application, I am sending an object containing a date
{destinationId: ", destinationTypeId:" 1 ", destination:" 2015-12-08T08: 00: 00-05: 00 "}
In my side dto
for my meeting. I have
@DateTimeFormat(iso=DateTimeFormat.ISO.DATE_TIME)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime appointmentDate;
In my dependencies, I have a jackson data type-jsr310-2.6.3
I get this error
rg.springframework.http.converter.HttpMessageNotReadableException: Failed to read document: text '2015-12-08T13: 00: 00.000Z' could not be parsed, unverified text found in index 23 (via the reference chain: server.dto.AppointmentDto ["appointmentDate"]); nested exception com.fasterxml.jackson.databind.JsonMappingException: text '2015-12-08T13: 00: 00.000Z' cannot be parsed, text unchecked was found at index 23 (via the chain of links: server.dto.AppointmentDto ["appointmentDate" ])
tried only with DateTimeFormat, only with JsonDeserialize and both, but get the same error.
Edit
@RequestMapping(value = "/rest")
@RestController
public class LodgerController {
@RequestMapping(value = "/lodgers/{lodgerId}/appointments", method = RequestMethod.POST)
public Long createAppointmentsByLodgerId(@PathVariable("lodgerId") Long lodgerId, @RequestBody AppointmentDto appointmentDto) {
return appointmentService.save(appointmentDto);
}
}
public class AppointmentDto {
private Long appointmentId;
private Long appointmentTypeId;
private Long lodgerId;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime appointmentDate;
public AppointmentDto() {
}
}
<form id="lodgerAppointmentForm" class="form-horizontal" role="form">
<input type="hidden" id="lodgerId" name="lodgerId">
<input type="hidden" id="lodgerAppointmentId" name="appointmentId">
<div class="form-group">
<label for="lodgerAppointmentDate" class="col-sm-2 control-label">Date</label>
<div class="col-sm-10">
<div class="input-group date" id="appointmentDatepicker" >
<input type="text" class="form-control" id="lodgerAppointmentDate" name="appointmentDate">
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar">
</span>
</span>
</div>
</div>
</div>
</form>
var locale = navigator.languages ? navigator.languages[0] : (navigator.language || navigator.userLanguage);
moment().locale(locale);
$('#appointmentDatepicker').datetimepicker({
format: 'DD/MM/YYYY H:mm',
allowInputToggle: true
});
var lodgerId = $('#lodgerId').val();
var type = "post";
var url = "http://localhost:8080/rest/lodgers/" + lodgerId + "/appointments";
var data = transForm.serialize('#lodgerAppointmentForm');
data.appointmentDate = $('#appointmentDatepicker').data('DateTimePicker').date().format();
data.lodgerId = lodgerId;
data = JSON.stringify(data);
jQuery.ajax({
type: type,
url: url,
contentType: "application/json",
data: data,
success: function (data, status, jqXHR) {
},
error: function (jqXHR, status) {
}
});
transform.js https://github.com/A1rPun/transForm.js/blob/master/src/transForm.js
bootstrap datetimepicker https://github.com/Eonasdan/bootstrap-datetimepicker
2015-12-09T08: 00: 00-05: 00 (ISO 8601)
DateTimeFormatter.ISO_LOCAL_DATE_TIME, : 2015-12-09T08: 00: 00 (ISO 8601)
, ,