使用对象映射器反序列化具有空值的属性

问题描述

我有一个已经序列化的JSON字符串。从源进行序列化时,不会忽略空属性值。因此,对象的序列化输出类似于:

"person": {
  "name": "foo","surname": null
}

现在,如果我在Java中使用对象映射器在上面进行反序列化,则会引发异常,并指出不可用的值。对象映射器有什么方法可以将“姓”反序列化为“空”?我可以配置对象映射器在这种情况下不失败吗?

解决方法

//...
    for (int i = 0; i < arr.length; i++) {
        int d = arr[i];
        if (check[d] != 0) {
            System.out.printf("Duplicate value %d found at index %d,first value is at %d%n",d,i,check[d] - 1);
            noDuplicates = false;
        }
        check[d] = i + 1; // storing index of the digit instead of its count
    }

输出

Input: [9,8,7,6,5,4,3,2,8]
Duplicate value 8 found at index 8,first value is at 1
Missing value: 1

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...