We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
使用JSONObject.getObject 将JSONObject转为bean时;JSON.config全局设置的Feature.SupportSmartMatch不生效 涉及api:com.alibaba.fastjson2.JSONObject#getObject(java.lang.String, java.lang.Class)
import java.util.Map; import org.assertj.core.api.Assertions; import org.junit.Before; import org.junit.Test; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONReader; import lombok.Data; public class ObjToBeanFeatureTest { @Before public void setUp() throws Exception { JSON.config(JSONReader.Feature.SupportSmartMatch, false); } @Test public void getObjectNoSupportGlobalConfig() { String text = "{\"appId\":\"com.xxx.xxx\"}"; // 没有设置,无问题 Bean bean1 = JSON.parseObject(text, Bean.class); Assertions.assertThat(bean1.appID).isEqualTo(null); // 全局设置智能匹配 JSON.config(JSONReader.Feature.SupportSmartMatch, true); Bean bean2 = JSON.parseObject(text, Bean.class); Assertions.assertThat(bean2.appID).isEqualTo("com.xxx.xxx"); Map<String, Object> jsonObject = JSON.parseObject(text); Assertions.assertThat(jsonObject.get("appId")).isEqualTo("com.xxx.xxx"); JSONObject obj = new JSONObject(); obj.put("v1", jsonObject); // 不传 Feature,无法正确反序列化 Bean bean3 = obj.getObject("v1", Bean.class); Assertions.assertThat(bean3.appID).isEqualTo(null); // 传 Feature,可以正确反序列化 Bean bean4 = obj.getObject("v1", Bean.class, JSONReader.Feature.SupportSmartMatch); Assertions.assertThat(bean4.appID).isEqualTo("com.xxx.xxx"); } @Data private static class Bean { private String appID; } }
JSONObject.getObject 不传Feature 时,应该复用全局配置。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
问题描述
使用JSONObject.getObject 将JSONObject转为bean时;JSON.config全局设置的Feature.SupportSmartMatch不生效
涉及api:com.alibaba.fastjson2.JSONObject#getObject(java.lang.String, java.lang.Class)
环境信息
重现步骤
期待的正确结果
JSONObject.getObject 不传Feature 时,应该复用全局配置。
The text was updated successfully, but these errors were encountered: