Optional JsonPath using Jayway

后端 未结 1 1666
别那么骄傲
别那么骄傲 2021-02-19 09:39

Question:

I have a service that takes in a JSON string as input. The JSON schema is different every time where some fields are

1条回答
  •  走了就别回头了
    2021-02-19 10:43

    I realized what I did wrong. The DEFAULT_PATH_LEAF_TO_NULL option only takes care of leaf nodes. For example:

    Sample Json

    {
        "foo":{
            "bar":"value"
        }
    }
    

    If $.foo.tmp is queried, JsonPath will return null as tmp is suppose to be a leaf node.

    If $.tmp.tmp2 is queried, JsonPath will throw a

    com.jayway.jsonpath.PathNotFoundException as tmp isn't a leaf and is not present.

    In order to bypass this, one should use Option.SUPPRESS_EXCEPTIONS.

    0 讨论(0)
提交回复
热议问题