gpt4 book ai didi

java - ProcessingException : org. codehaus.jackson.map.JsonMappingException:无法从 START_ARRAY token 中反序列化 X 的实例

转载 作者:行者123 更新时间:2023-11-30 06:39:03 25 4
gpt4 key购买 nike

private <T> T[] getObjects(Class<T> tClass, String version) {
String subUrl = "/versions/" + version;
return ClientBuilder.newClient()
.target(url)
.request()
.get(new GenericType<T[]>(tClass) {});
}

这里是 json 对象

[  
{
"id":1,
"name":"test",
"country":"USA"
},
{
"id":2,
"name":"test_1",
"country":"cameroon"
}
]

getObjects方法的调用:

X[] x = getObjects(X.class, currentVersionName);

我得到这个异常:

Caused by: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of X out of START_ARRAY token
at [Source: org.apache.http.conn.EofSensorInputStream@3eb91815; line: 1, column: 1]
at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:219)
at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:212)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromArray(BeanDeserializer.java:875)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:597)
at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2704)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1315)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)
at org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.readFrom(AbstractReaderInterceptorContext.java:66)
at org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:56)
at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:248)
... 38 more

我使用这些依赖项:

<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.1.2.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>3.1.2.Final</version>
</dependency>

最佳答案

尝试改变:

private <T> T[] getObjects(Class<T> tClass, String version)

private <T> T[] getObjects(Class<T[]> tClass, String version)

你的来电者将是

X[] x = getObjects(X[].class, currentVersionName);

关于java - ProcessingException : org. codehaus.jackson.map.JsonMappingException:无法从 START_ARRAY token 中反序列化 X 的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44714976/

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