From 67aebf7e5d9157bba99b7bcb0b57e4e647000d2e Mon Sep 17 00:00:00 2001 From: rowstop Date: Mon, 5 Feb 2024 10:08:15 +0800 Subject: [PATCH] add testcase,for issue #2230 --- .../fastjson2/issues_2200/Issue2230.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 core/src/test/java/com/alibaba/fastjson2/issues_2200/Issue2230.java diff --git a/core/src/test/java/com/alibaba/fastjson2/issues_2200/Issue2230.java b/core/src/test/java/com/alibaba/fastjson2/issues_2200/Issue2230.java new file mode 100644 index 0000000000..3536488907 --- /dev/null +++ b/core/src/test/java/com/alibaba/fastjson2/issues_2200/Issue2230.java @@ -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 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(); + } +}