Visitar URL original
JSONPath对于list的处理,当取值为null的时候,是否可以增加一个选项设置把null value设置到list里面,而不是直接忽略 · Issue #3607 · alibaba/fastjson · GitHub
Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.
This repository was archived by the owner on Jul 29, 2026. It is now read-only.

JSONPath对于list的处理,当取值为null的时候,是否可以增加一个选项设置把null value设置到list里面,而不是直接忽略 #3607

Open

Description

@liverliu

对如下数据使用:JSONPath.eval(json, "$.data.dataRows[*].dataFields[*].value"),返回了6个元素的list,是否可以增加一种配置可以返回7个元素的list,其中首元素是null;当前默认的忽略处理,业务代码里面无法正确的映射元素的顺序,导致错误。

也就是希望有种方式,能让我取出的list是下面这种形式:
[null,"C3736",1621126800000,"**","29***6",1605456000000,"240397"]

而不是现在这样:
["C3736",1621126800000,"**","29***6",1605456000000,"240397"]

jayway的jsonpath是有这种能力的
Configuration conf = Configuration.defaultConfiguration().addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL);
return JsonPath.using(conf).parse(json).read(path);

{
"data": {
"dataRows": [
{
"dataFields": [
{
"id": 1332,
"name": "gmtRegular",
"status": "success",
"valueType": "DATE"
},
{
"id": 302,
"name": "deptNo",
"status": "success",
"value": "C3736",
"valueType": "STRING"
},
{
"id": 143,
"name": "gmtOrigRegular",
"status": "success",
"value": 1621126800000,
"valueType": "DATE"
},
{
"id": 135,
"name": "name",
"status": "success",
"value": "",
"valueType": "STRING"
},
{
"id": 133,
"name": "workNo",
"status": "success",
"value": "29
*6",
"valueType": "STRING"
},
{
"id": 140,
"name": "gmtEntry",
"status": "success",
"value": 1605456000000,
"valueType": "DATE"
},
{
"id": 199,
"name": "superWorkNo",
"status": "success",
"value": "240397",
"valueType": "STRING"
}
]
}
]
},
"status": "success",
"success": true
}

Activity

  1. changed the title [-]对于list的处理,当取值为null的时候,是否可以增加一个选项设置把null value设置到list里面,而不是直接忽略[/-] [+]JSONPath对于list的处理,当取值为null的时候,是否可以增加一个选项设置把null value设置到list里面,而不是直接忽略[/+] on Jan 5, 2021
  2. github-ganyu commented on Jan 6, 2021

    @github-ganyu
    Contributor

    I think this is a good proposal and I try to submit a PR.

  3. github-ganyu commented on Jan 8, 2021

    @github-ganyu
    Contributor

    我写了一个重载方法,第二个参数传false代表不忽略空值:
    JSONPath.eval(json, "$.data.dataRows[].dataFields[].value", false);
    15ac107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions