0

This is my FeignClient:

@FeignClient(name="${mongo.service.id}", url="${mongo.service.url}", configuration = FeignConfig.class)
public interface MongoAtmResetDataInterface {
    String requestMappingPrefix = "/api/atmResetData";

    @GetMapping(path = requestMappingPrefix + "/brinksDateTime")
    LocalDateTime fetchLastBrinksDateTime();
}

This is the call to the feign endpoint:

private String fetchLastBrinksTime() {
    return mongoAtmResetDataInterface.fetchLastBrinksDateTime()
       .toLocalDate()
       .format(DateTimeFormatter.ofPattern(DATE_FORMAT));
}

I get the following exception:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: 
Cannot construct instance of `java.time.LocalDateTime` (no Creators, like default construct, exist): 
no String-argument constructor/factory method to deserialize from String value ('10-12-2019T14:01:39')

I do have a LocalDateTime converter in my SpringMvcConfig class & a contract in my FeignConfig class. Can anyone help- what am I missing?

Rotem Linik
  • 155
  • 2
  • 13
  • Does this answer your question? [JSON parse error: Can not construct instance of java.time.LocalDate: no String-argument constructor/factory method to deserialize from String value](https://stackoverflow.com/questions/45863678/json-parse-error-can-not-construct-instance-of-java-time-localdate-no-string-a) – Prabhjot Singh Kainth Feb 27 '20 at 09:50
  • I already hold converters in my MvcConfigurer so sadly that does not answer:( – Rotem Linik Feb 27 '20 at 10:01

1 Answers1

0

Spring MVC using deserialize will make to an Array. But Feign call the object method with ArrayList. so you can not deserialize LocalDate.

So you can add this setting in pom.xml

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

And add this to deserialize model. (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule, com.fasterxml.jackson.datatype.jsr310.JSR310Module)

@Bean
public ObjectMapper serializingObjectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    objectMapper.registerModule(new JavaTimeModule());
    return objectMapper;
}

wish can help you.

石荒人
  • 753
  • 1
  • 6
  • 11