-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
core/src/test/java/com/alibaba/fastjson2/issues_2200/Issue2230.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.alibaba.fastjson2.issues_2200; | ||
|
||
import com.alibaba.fastjson2.JSONArray; | ||
import com.alibaba.fastjson2.JSONObject; | ||
import com.alibaba.fastjson2.JSONWriter; | ||
import lombok.Data; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
/** | ||
* @author 张治保 | ||
* @since 2024/2/5 | ||
*/ | ||
public class Issue2230 { | ||
@Test | ||
void test(){ | ||
JSONObject dfDtoJson = new JSONObject(); | ||
dfDtoJson.put( | ||
"componentList", | ||
new JSONArray().fluentAdd( | ||
new JSONObject().fluentPut( | ||
"props", | ||
new JSONObject() | ||
.fluentPut("compTypeName", "test11") | ||
.fluentPut("name", "test22") | ||
) | ||
) | ||
); | ||
DynFormDto newDfDto = dfDtoJson.toJavaObject(DynFormDto.class); | ||
System.out.println(newDfDto.getComponentList().get(0).getProps()); | ||
} | ||
@Data | ||
static class DynFormDto { | ||
private List<DynFormComponentDto> componentList; | ||
private String notes; | ||
} | ||
@Data | ||
static class DynFormComponentDto implements Serializable { | ||
private JSONObject props; // 组件完整配置 | ||
// 这个方法会导致props字段反序列化结果出现{"h":{***}}结构 | ||
public DynFormComponentDto props(IFormComponent comp) { | ||
this.props = (JSONObject) JSONObject.from(comp, JSONWriter.Feature.FieldBased); | ||
return this; | ||
} | ||
} | ||
interface IFormComponent { | ||
String getCompTypeName(); | ||
String getName(); | ||
} | ||
} |