alibaba / alibaba/fastjson2

[QUESTION] Json 数据中的同一个字段是否能够支持自动赋值给对应的类型?

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

Description

如下所示,返回的 `json` 数据种有一个 `value` 字段,该字段的值可能为 `int` 或者 `string` 类型,期望是能够根据数据的类型尝试自动解析到对应的字段上,另一个则返回 `null`,请问目前是否能够实现这种效果?
```java
@Data
public class Test {

@JSONField(name = "value")
private Integer valueA;

@JSONField(name = "value")
private String valueB;

}
```

Contributor guide

Open the contributing guide

Research direction

The issue describes a Java Test class with two @JSONField(name = "value") properties, one Integer and one String. Start by checking the deserialization documentation and existing tests for duplicate JSON field names and type-dependent assignment. Done would be a confirmed supported behavior with coverage, or a clearly documented limitation and alternative.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.