gpt4 book ai didi

java - 如何将 graphql-java-extended-scalars DateTime 与 Jackson 一起使用

转载 作者:行者123 更新时间:2023-12-02 09:39:19 25 4
gpt4 key购买 nike

我收到此错误

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `org.joda.time.DateTime` (although at least one Creator exists): no suitable creator method found to deserialize from Number value (1564191690.702000000)
at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: br.com.b2breservas.api.dto.FakeReservationPaginationInput["filter"]->br.com.b2breservas.api.dto.FakeReservationPaginationInputFilter["end"])

Java

import org.joda.time.DateTime;

public class FakeReservationPaginationInput {

FakeReservationPaginationInputFilter filter;

CheckoutPermissionInput permission;


}

public class FakeReservationPaginationInputFilter {
Integer limit;
List<String> statuses;
String query;
DateTime start;
DateTime end;
}

private final ObjectMapper objectMapper = new ObjectMapper()
.registerModule(new ParameterNamesModule())
.registerModule(new Jdk8Module())
.registerModule(new JavaTimeModule());

// where the error pops up
FakeReservationPaginationInput input = objectMapper
.convertValue(dataFetchingEnvironment.getArgument("input"), FakeReservationPaginationInput.class);

我正在发送

{
...,
start: "2019-07-27T01:32:33.116Z",
end: "2019-07-27T11:32:33.116Z"
}

这基本上是

{
...,
start: moment().format(),
end: moment().format()
}

z

架构

scalar DateTime

input QueryReservationsInput {
filter: ReservationFilter
permission: CheckoutPermissionInput
}

input ReservationFilter {
query: String
statuses: [String]
limit: Int
end: DateTime!
start: DateTime!
}

input CheckoutPermissionInput {
type: String
ref_id: Int
ref_name: String
chain_id: Int
chain_name: String
}

最佳答案

这个问题实际上与 GraphQL 无关......它是关于配置 Jackson 来反序列化 JodaTime 类型。尝试正确地隔离您的问题,因为这样可以消除大量噪音,并使问题更容易回答并为更广泛的受众所理解。

无论如何,您正在注册 JavaTimeModule,但您却使用了 JodaTime。您需要JodaModule相反。

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.9.5</version>
</dependency>

然后

mapper.registerModule(new JodaModule());

关于java - 如何将 graphql-java-extended-scalars DateTime 与 Jackson 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57228560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com