From 5b7fbbc9080af2e1a3a3c4fad2ce7cb4ef6f0fb7 Mon Sep 17 00:00:00 2001 From: "shaojin.wensj" Date: Sat, 25 Jun 2022 16:45:55 +0800 Subject: [PATCH] add testcase for issue #505 --- .../alibaba/fastjson2/issues/Issue505.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 core/src/test/java/com/alibaba/fastjson2/issues/Issue505.java diff --git a/core/src/test/java/com/alibaba/fastjson2/issues/Issue505.java b/core/src/test/java/com/alibaba/fastjson2/issues/Issue505.java new file mode 100644 index 0000000000..821a1dfe3e --- /dev/null +++ b/core/src/test/java/com/alibaba/fastjson2/issues/Issue505.java @@ -0,0 +1,26 @@ +package com.alibaba.fastjson2.issues; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson2.PropertyNamingStrategy; +import com.alibaba.fastjson2.filter.NameFilter; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class Issue505 { + @Test + public void test() { + Bean bean = new Bean(); + bean.userId = 101; + + String str = JSON.toJSONString(bean, NameFilter.of(PropertyNamingStrategy.PascalCase)); + assertEquals("{\"UserId\":101}", str); + JSONObject object = JSON.parseObject(str); + assertEquals(101, object.get("UserId")); + } + + public static class Bean { + public int userId; + } +}