alibaba / alibaba/fastjson2

[BUG]TypeUtils.castToJavaBean对Boolean支持的问题

Open Beginner friendly
#7,842 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

### 问题描述
com.alibaba.fastjson.util.TypeUtils#castToJavaBean(java.lang.Object, java.lang.Class)方法在转化为Boolean类型时候与fastjson严重不一致,所有的String都会走到StringToAny方法,非"true"会全部返回false
而com.alibaba.fastjson2.function.impl.ToBoolean中实现了为String类型的多种值判断,其中的String类型则永远走不到

### 环境信息
*请填写以下信息:*

- 版本信息fastjson 2.0.31

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

1.使用代码
```
TypeUtils.castToJavaBean("TRUE", Boolean.class)
```

### 期待的正确结果
*对您期望发生的结果进行清晰简洁的描述。*
希望可以支持相关字符串,如TRUE, 字符串1,True等,或者能与fastjson1保持一致的处理:

Contributor guide

Open the contributing guide

Research direction

Start at com.alibaba.fastjson.util.TypeUtils#castToJavaBean and compare its Boolean conversion path with com.alibaba.fastjson2.function.impl.ToBoolean. Reproduce the issue with TypeUtils.castToJavaBean("TRUE", Boolean.class), then verify the supported string forms and fastjson1-compatible behavior. Done means non-"true" strings are no longer uniformly converted to false, with regression coverage for the corrected behavior.

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
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.