wtorek, 25 października 2016

Handling with LocalDate issues in Spring Boot.




If you have LocalDate field in your entities you can get errors like:


Servlet.service() for servlet [dispatcherServlet] in context with path [] 
threw exception [Request processing failed; nested exception is 
org.springframework.orm.jpa.JpaSystemException: could not deserialize; 
nested exception is org.hibernate.type.SerializationException: 
could not deserialize] with root cause

or:


Failed to read HTTP message: 
org.springframework.http.converter.HttpMessageNotReadableException: 
Could not read document: Can not construct instance of java.time.LocalDate: 
no suitable constructor found, can not deserialize from Object value 
(missing default constructor or creator, or perhaps need to add/enable type 
information?)


nested exception is com.fasterxml.jackson.databind.JsonMappingException: 
Can not construct instance of java.time.LocalDate: 
no suitable constructor found, can not deserialize from Object value 
(missing default constructor or creator, or perhaps need to add/enable 
type information?)



To solve that, insert in pom.xml:


                <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-java8</artifactId>
  </dependency>
  <dependency>
   <groupId>com.fasterxml.jackson.datatype</groupId>
   <artifactId>jackson-datatype-jsr310</artifactId>
   </dependency>


Brak komentarzy:

Prześlij komentarz