fastjson2/docs/jsonpath_typed.md
2022-11-16 23:33:34 +08:00

481 B
Raw Permalink Blame History

在大数据场景下我们会对JSONPath要求返回指定的类型这个时候JSONPath可以提供指定类型来返回这样更高效也更安全。

1. 接口定义

public class JSONPath {
    public static JSONPath of(String path, Type type);
}

2. 例子

String str = "{\"id\":1001, \"name\":\"DataWorks\"}";
JSONPath jsonPath = JSONPath.of("id", Long.class);

Long expected = 1001L;
assertEquals(expected, jsonPath.extract(json));