Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从FaignClient端点返回LocalDateTime?_Java_Spring_Rest_Spring Cloud Feign_Localdate - Fatal编程技术网

Java 如何从FaignClient端点返回LocalDateTime?

Java 如何从FaignClient端点返回LocalDateTime?,java,spring,rest,spring-cloud-feign,localdate,Java,Spring,Rest,Spring Cloud Feign,Localdate,这是我的假客户: @FeignClient(name="${mongo.service.id}", url="${mongo.service.url}", configuration = FeignConfig.class) public interface MongoAtmResetDataInterface { String requestMappingPrefix = "/api/atmResetData"; @GetMapping(path = requestMappi

这是我的假客户:

@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();
}
这是对外部端点的调用:

private String fetchLastBrinksTime() {
    return mongoAtmResetDataInterface.fetchLastBrinksDateTime()
       .toLocalDate()
       .format(DateTimeFormatter.ofPattern(DATE_FORMAT));
}
我得到以下例外情况:

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')
在我的SpringMvcConfig类中有一个LocalDateTime转换器&在我的FeignConfig类中有一个契约。
有人能帮忙吗?我缺少什么?

使用反序列化的Spring MVC将生成一个数组。但是用ArrayList调用object方法。因此不能反序列化LocalDate

因此,您可以在pom.xml中添加此设置

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

愿望可以帮助你。

这能回答你的问题吗?我已经在我的MVCConfigure中保存了转换器,非常遗憾,无法回答:(谢谢,但我尝试了这个方法,但仍然得到了完全相同的例外情况Maybe,因为这是指序列化,我的问题是反序列化?尝试另一种方法?当LocalDateTime是响应的一部分时,此解决方案很好,在我的情况下,它是响应..仍在寻找解决方案
@Bean
public ObjectMapper serializingObjectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    objectMapper.registerModule(new JavaTimeModule());
    return objectMapper;
}