I use spring boot and spring 4.
@EntityScan(basePackageClasses = {ServerApplication.class, Jsr310JpaConverters.class})
@SpringBootApplication
@EnableCaching
public class ServerApplication {
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
}
I try to use Java 8 LocalDate.
In the json for the date i have
birthdate: "1969-12-29"
On the server side for this field i have
@DateTimeFormat(iso=DateTimeFormat.ISO.DATE)
private LocalDate birthdate;
I get this error
org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not instantiate value of type [simple type, class java.time.LocalDate] from String value ('1969-12-29'); no single-String constructor/factory method
Edit
Dto send via ajax
public class LodgerInformationDto {
private Long lodgerId;
private String firstName;
private String lastName;
@DateTimeFormat(iso=DateTimeFormat.ISO.DATE)
private LocalDate birthdate;
}
Controller Rest class
@RequestMapping(value = "/lodgers", method = RequestMethod.POST)
public LodgerInformationDto createLodger(@RequestBody @Valid final LodgerInformationDto lodgerDto) {
return lodgerService.save(lodgerDto);
}
with this dependencies: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.6.3
this line in the application.properties spring.jackson.serialization.write-dates-as-timestamps=false
that work.
@DateTimeFormatdoes nothing in that case. Also, that property you added serves no purpose for the deserializing you're doing.