Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 不支持的JSONPath,或是语法解析错误? #2401

Closed
SMFDrummer opened this issue Apr 4, 2024 · 7 comments
Closed

[BUG] 不支持的JSONPath,或是语法解析错误? #2401

SMFDrummer opened this issue Apr 4, 2024 · 7 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@SMFDrummer
Copy link

问题描述

以下是我的JSON数据

{
        	"objects": [
        		{
        			"objclass": "GamePropertySheet",
        			"aliases": [
        				"DefaultGameProps"
        			],
        			"objdata": {
        				"Plants": [
        					"plant1",
        					"plant2"
        				]
        			}
        		}
        	]
        }

我使用的JSONPath为:$.objects[?(@.aliases[0] == 'DefaultGameProps')].objdata
目的为需要返回objdata此JSONObject

但运行时报错:

Exception in thread "main" com.alibaba.fastjson2.JSONException: not support operator : 
	at com.alibaba.fastjson2.JSONPath.parseOperator(JSONPath.java:1018)
	at com.alibaba.fastjson2.JSONPathParser.parseFilter(JSONPathParser.java:711)
	at com.alibaba.fastjson2.JSONPathParser.parseArrayAccess(JSONPathParser.java:254)
	at com.alibaba.fastjson2.JSONPathParser.parse(JSONPathParser.java:95)
	at com.alibaba.fastjson2.JSONPath.of(JSONPath.java:475)
	at com.alibaba.fastjson2.JSONPath.eval(JSONPath.java:70)

环境信息

请填写以下信息:

  • OS信息: WIndows 11 23H2 (22631.3007)
  • JDK信息: OracleJDK 21
  • 版本信息:Fastjson2 2.0.47

重现步骤

Kotlin:

fun main() {
    val str = """
        {
        	"#comment": "All PropertySheet objects should go here",
        	"version": 1,
        	"objects": [
        		{
        			"objclass": "GamePropertySheet",
        			"aliases": [
        				"DefaultGameProps"
        			],
        			"objdata": {
        				"Plants": [
        					"plant1",
        					"plant2"
        				]
        			}
        		}
        	]
        }
    """.trimIndent()
    println(JSONPath.eval(str,"$.objects[?(@.aliases[0] == 'DefaultGameProps')].objdata"))
}

期待的正确结果

{"Plants": ["plant1","plant2"]}

@SMFDrummer SMFDrummer added the bug Something isn't working label Apr 4, 2024
@SMFDrummer
Copy link
Author

经过测试,这与是否将str序列化为JSONObject无关

@SMFDrummer SMFDrummer reopened this Apr 4, 2024
@SMFDrummer
Copy link
Author

SMFDrummer commented Apr 4, 2024

经过测试,JSONPath.eval转为JSONPath.extract依然无法使用

Exception in thread "main" com.alibaba.fastjson2.JSONException: not support operator : 
	at com.alibaba.fastjson2.JSONPath.parseOperator(JSONPath.java:1018)
	at com.alibaba.fastjson2.JSONPathParser.parseFilter(JSONPathParser.java:711)
	at com.alibaba.fastjson2.JSONPathParser.parseArrayAccess(JSONPathParser.java:254)
	at com.alibaba.fastjson2.JSONPathParser.parse(JSONPathParser.java:95)
	at com.alibaba.fastjson2.JSONPath.of(JSONPath.java:475)
	at com.alibaba.fastjson2.JSONPath.extract(JSONPath.java:55)

@SMFDrummer
Copy link
Author

经过测试,此为完全JSONPath解析问题,与待解析的jsonString无关

@wenshao wenshao added this to the 2.0.49 milestone Apr 5, 2024
@wenshao
Copy link
Member

wenshao commented Apr 5, 2024

目前还不支持,但应该要支持的

@SMFDrummer
Copy link
Author

已暂时改为使用Snack3库,期待fastjson2的更新!

@wenshao
Copy link
Member

wenshao commented Apr 6, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.49-SNAPSHOT/
已经支持,请帮忙用2.0.49-SNAPSHOT验证,2.0.49版本预计在月底发布

@wenshao wenshao added the fixed label Apr 6, 2024
wenshao added a commit that referenced this issue Apr 6, 2024
@wenshao
Copy link
Member

wenshao commented Apr 14, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants