我有这行代码:
feedInfoResponse = feedInfoClient.retrieve(GET(uri).header("accept", "application/json"), FeedInfoResponse.class).blockingFirst();
正在投掷:
Caused by: io.micronaut.http.codec.CodecException: Cannot decode bytes with value [{
"feed_ts" : 1692674294,
"feed_v" : "1"
}] to type: FeedInfoResponse
此代码正在运行:
String response = feedInfoClient.retrieve(GET(uri).header("accept", "application/json")).blockingFirst();
ObjectMapper objectMapper = new ObjectMapper();
try {
feedInfoResponse = objectMapper.readValue(response, FeedInfoResponse.class);
System.out.println("FeedInfoResponse object: " + feedInfoResponse);
} catch (Exception e) {
e.printStackTrace();
}
所以我的假设是 micronaut 的 netty 默认 httpclient 使用另一个 json 解析器,然后是 jackson。 有什么方法可以将这些东西用于我的第一个示例吗?
中的
[{
Cannot decode bytes with value [{
"feed_ts" : 1692674294,
"feed_v" : "1"
}] to type: FeedInfoResponse
表示控制器返回一个数组。因此,如果你这样做,它应该有效
import io.micronaut.core.type.Argument;
feedInfoResponse = feedInfoClient.retrieve(
GET(uri).header("accept", "application/json"),
Argument.listOf(FeedInfoResponse.class)
).blockingFirst();