objectmapper.convertvalue()-缺少必需的属性;即使财产存在

13z8s7eq  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(473)

这是我的java代码
函数应该返回一个indexdto(外部,不在我的控件中)类型的对象,该对象从httpresponseMap而来,这是一个okhttpget服务调用响应:

objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

JSONObject responseObject = objectMapper.readValue(httpResponse.body().string(), JSONObject.class);
return objectMapper.convertValue(responseObject, IndexDto.class);

事情是这样的
在objectmapper.convertvalue()处引发以下错误:

java.lang.IllegalArgumentException: Cannot construct instance of `com.orgname.package.model.AutoValue_IndexHbaseDetailsDto$Builder`, problem: Missing required properties: tableName
 at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: com.orgname.package.model.AutoValue_IndexDto$Builder["hbase"])
java.util.concurrent.ExecutionException: java.lang.NullPointerException

到目前为止我调查了什么?
我已经验证了jsonobject(responseobject)具有indexdto类所要求的正确结构。此外,我交叉检查了json响应中“hbase”下是否存在“table\u name”。我还尝试过将其他objectmapper反序列化功能设置为false,但没有任何效果。
下面是json响应(httpresponse)的快照:

{
    "index_name": "some_index_name",
    "hbase": {
        "connection": "some_conn_name",
        "table_name": "some_tab_name",
        "column_family": "index",
        "column_qualifier": "document"
    }
}

indexdto类代码段:

public abstract class IndexDto {
    public IndexDto() {
    }

    public static IndexDto.Builder builder() {
        return (new com.orgname.package.model.AutoValue_IndexDto.Builder()).setProperties(Collections.emptyMap());
    }

    public static IndexDto.Builder builder(IndexDto source) {
        return new com.orgname.package.model.AutoValue_IndexDto.Builder(source);
    }

    @ApiModelProperty(
        required = false,
        value = "hbase specific index configuration"
    )
    @JsonProperty("hbase")
    @Nullable
    public abstract IndexHbaseDetailsDto getHbase();
}

抽象类IndexhbaseDetailsTo:

@ApiModelProperty(
    required = true,
    value = "name of index's hbase table"
)
@JsonProperty("table_name")
public abstract String getTableName();

我需要什么?
救命啊!谢谢。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题