fastjson2/docs/jsonpath_typed.md

18 lines
481 B
Markdown
Raw Normal View History

2022-11-16 23:33:34 +08:00
在大数据场景下我们会对JSONPath要求返回指定的类型这个时候JSONPath可以提供指定类型来返回这样更高效也更安全。
# 1. 接口定义
```java
public class JSONPath {
public static JSONPath of(String path, Type type);
}
```
# 2. 例子
```java
String str = "{\"id\":1001, \"name\":\"DataWorks\"}";
JSONPath jsonPath = JSONPath.of("id", Long.class);
Long expected = 1001L;
assertEquals(expected, jsonPath.extract(json));
```