Skip to content

Commit

Permalink
add testcase,for issue #2230
Browse files Browse the repository at this point in the history
  • Loading branch information
rowstop authored and wenshao committed Feb 5, 2024
1 parent 745fddf commit 67aebf7
Showing 1 changed file with 52 additions and 0 deletions.
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();
}
}

0 comments on commit 67aebf7

Please sign in to comment.