alibaba / alibaba/fastjson2

[BUG]fastjson2 JSONObject.from("test")报错

Open
#2,413 1 comment 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

### 问题描述
fastjson2的如下代码报错:
JSONObject.from("test");

### 环境信息
- 版本信息:[e.g.:Fastjson2 2.0.48]

### 重现步骤
*如何操作可以重现该问题:*

1. 使用 `JSONObject.from` 方法
3. 出现 ` java.lang.ClassCastException: class java.lang.String cannot be cast to class com.alibaba.fastjson2.JSONObject (java.lang.String is in module java.base of loader 'bootstrap'; com.alibaba.fastjson2.JSONObject is in unnamed module of loader 'app')
at com.alibaba.fastjson2.JSONObject.from(JSONObject.java:2028)` 错误
```java
JSONObject.from("test");
```

### 期待的正确结果
这个问题出现的场景是,传给JSONObject.from的参数值是Object类型,该类型是动态的,可能是基本类型,也可能是包含字段的类型

Contributor guide

Open the contributing guide

Research direction

Start with com.alibaba.fastjson2.JSONObject.from and reproduce the reported ClassCastException from JSONObject.java:2028 using JSONObject.from("test"). Check behavior when the Object argument is a basic value or an object with fields; done means supported dynamic values no longer fail with this cast error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.