1

We have upgraded springboot 1.5.3 to 2.0. We are getting below exception while reading existing documents.

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.time.Instant]

Below mongo document and entity class for the same. With previous springboot version It was working fine. Now I am getting exception during mongoTemplate.findOne() API call.

{
     "_id": "a884b47533a2f2596",
     "_class": "com.A.B.C.model.Entity1",
     "field1": "00006353",
     "field2": "384493",
     "field3": "327274",
     "date": "2018-09-03T08:25:22.461Z"
 }
public class Entity1 {
     @Id
     private String id;
     @Indexed
     private String field1;
     @Indexed
     private String field2;
     @Indexed
     private String field3;
     private Instant date;
 }
doga
  • 471
  • 2
  • 9
  • 20

1 Answers1

3

This issue is about Java 8 dates and its serialization/deserialization. You should create a custom instance of objectMapper and then inject it in your mongoTemplate.

Here it is explained well: https://gist.github.com/corbtastik/7727bb870751f488ab30383aa72c834d

Also, you need to add the maven dependencies:

<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jsr310</artifactId>
</dependency>

Good luck!

Juan Bermudez
  • 430
  • 3
  • 6