alibaba / alibaba/fastjson2

[FEATURE]有没有在注解中直接支持JSONPath的计划?

Open
#579 4 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

对接接口时,尤其是不同语言系统之间的相互对接,传过来的json体习惯也不相同。经常会出现多层结构但是只需要值的情况。
比如:
```json
{
"Id": "94fcc55b2aba437c9a7c1a2765a3e378",
"MsgType": 3,
"TerminalId": "YK",
"LaneName": "15",
"Item": {
"Datetime": "2022-07-19T10:03:37.575796+08:00",
"Msg": "这是一条测试消息"
}
}
```
实际上接收方不需要item中的层级只需要里面的值。
如果可以在定义的bean中直接指定@JsonProperty("jsonPath")的形式,就能更直接的在转换层处理层级结构,而不是接收到json串之后再自行处理;同时这还能解决json扁平化的需求。
例如:
```
public class Bean{
@JsonProperty("Id")
public String id;
@JsonProperty("$.Item.Msg")
public String Msg;
}
```

Contributor guide

Open the contributing guide

Research direction

The issue names no files or tests. Start by tracing annotation processing and bean deserialization in fastjson2, then determine how @JsonProperty("$.Item.Msg") should interact with ordinary property names. Done means the supported annotation behavior is specified and covered for nested extraction and JSON flattening.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.