alibaba / alibaba/fastjson2

[BUG]JSONPath.contains和JSONPath.eval输出结果不一致

Open Beginner friendly
#7,771 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 问题描述
JSONPath.contains结果为false,但JSONPath.eval可以取到值

### 环境信息
- OS信息: NA
- JDK信息:Openjdk 21.0.8
- 版本信息:Fastjson2 2.0.60

### 重现步骤
private void test1() {
String s = """
{"status": 200}
""";

boolean contains = JSONPath.contains(s, "$.status");
Object eval = JSONPath.eval(s, "$.status");
System.out.println(eval); // 返回 200
System.out.println(contains); // 返回 false 期望返回 true
}

Contributor guide

Open the contributing guide

Research direction

Start by running the provided Java reproduction against Fastjson2 2.0.60, then inspect JSONPath.contains and JSONPath.eval for how they process $.status. Add a regression test covering the shown JSON and path, and confirm that both methods consistently report the existing value.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.