异常错误:无法识别的类型:[null]在Jackson

cld4siwp  于 2022-11-08  发布在  其他
关注(0)|答案(1)|浏览(122)

这是我的方法,其中有这个错误

private <T> Mono<CarbonResponse<T>> evaluateVersion(Key key, String facts, boolean showTestResults) {
   return mapper.readValue(result,  new TypeReference<CarbonResponse<T>>() {}); // error here
}

其中,result是JSON字符串。
我的CarbonResponse.java

public class CarbonResponse<T> {
    int code;
    String message;
    DataV1<T> data;
}

DataV1.java

public class DataV1<T> {

    @JsonProperty(value = "rule_set_id")
    String ruleSetId;

    @JsonProperty(value = "version_id")
    String ruleSetVersionId;

    T result;

    @JsonProperty(value = "rules_evaluation_response")
    List<T> rulesEvaluationResponse;
}

平地机

implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.10.3'
 // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
 implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.10.3'

完整错误轨迹

java.lang.IllegalArgumentException: Unrecognized Type: [null]
    at com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1266)
    at com.fasterxml.jackson.databind.type.TypeFactory._fromParamType(TypeFactory.java:1480)
    at com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1250)
    at com.fasterxml.jackson.databind.type.TypeFactory.constructType(TypeFactory.java:670)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3197)
    at com.pharmeasy.carbon.client.CarbonClient.lambda$evaluateVersion$0(CarbonClient.java:321)
    at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:100)
    at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1705)
    at reactor.core.publisher.MonoZip$ZipCoordinator.signal(MonoZip.java:247)
    at reactor.core.publisher.MonoZip$ZipInner.onNext(MonoZip.java:329)

我能知道我错过了什么吗?
我想当我们有T的时候,这个new TypeReference<CarbonResponse<T>>() {}会给出null,但是我无法找到解决方案。

3zwtqj6y

3zwtqj6y1#

您只需使用

Mono<CarbonResponse<Void>>
new TypeReference<CarbonResponse<Void>

相关问题