From ea1cd5f8df3740a3026c41e1a6d00dee51b93cc0 Mon Sep 17 00:00:00 2001 From: lightsing Date: Thu, 7 May 2020 21:24:58 +0800 Subject: [PATCH 1/3] fix maven3 support --- pom.xml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f5dc25aa93..474e2278f6 100755 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ true true UTF-8 - 1.6 + 1.7 @@ -133,6 +133,7 @@ org.apache.maven.plugins maven-source-plugin + 3.2.0 attach-sources @@ -157,7 +158,9 @@ + org.apache.maven.plugins maven-javadoc-plugin + 3.2.0 attach-javadoc @@ -179,7 +182,9 @@ + org.apache.maven.plugins maven-gpg-plugin + 1.6 ${gpg.skip} @@ -322,6 +327,13 @@ provided + + org.jacoco + jacoco-maven-plugin + 0.7.6.201602180812 + provided + + org.eclipse.jetty jetty-server From c7b7f8de65d8c610189a6f324de4e3611eb06d14 Mon Sep 17 00:00:00 2001 From: "9908842844@qq.com" <990842844@qq.com> Date: Tue, 26 May 2020 22:49:07 +0800 Subject: [PATCH 2/3] fix issue 3084 --- .../fastjson/serializer/SerialContext.java | 4 ++ .../issue3084/TestRefWithQuote.java | 45 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/test/java/com/alibaba/fastjson/serializer/issue3084/TestRefWithQuote.java diff --git a/src/main/java/com/alibaba/fastjson/serializer/SerialContext.java b/src/main/java/com/alibaba/fastjson/serializer/SerialContext.java index c6263a9239..a65a9fe88a 100644 --- a/src/main/java/com/alibaba/fastjson/serializer/SerialContext.java +++ b/src/main/java/com/alibaba/fastjson/serializer/SerialContext.java @@ -59,6 +59,10 @@ protected void toString(StringBuilder buf) { } else if ((ch >= '0' && ch <='9') || (ch >= 'A' && ch <='Z') || (ch >= 'a' && ch <='z') || ch > 128) { buf.append(ch); continue; + } else if(ch == '\"'){ + buf.append('\\'); + buf.append('\\'); + buf.append('\\'); } else { buf.append('\\'); buf.append('\\'); diff --git a/src/test/java/com/alibaba/fastjson/serializer/issue3084/TestRefWithQuote.java b/src/test/java/com/alibaba/fastjson/serializer/issue3084/TestRefWithQuote.java new file mode 100644 index 0000000000..43947eb0ad --- /dev/null +++ b/src/test/java/com/alibaba/fastjson/serializer/issue3084/TestRefWithQuote.java @@ -0,0 +1,45 @@ +package com.alibaba.fastjson.serializer.issue3084; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + +public class TestRefWithQuote { + + public static class X { + private String x; + + public X(String x) { + this.x = x; + } + + public String getX() { + return x; + } + + public void setX(String x) { + this.x = x; + } + } + + @Test + public void testIssue3084() { + Map origin = new HashMap<>(); + TestRefWithQuote.X x = new TestRefWithQuote.X("x"); + origin.put("aaaa\"", x); + origin.put("bbbb\"", x); + + try { + String json = JSON.toJSONString(origin, true); + JSONObject root = JSON.parseObject(json); + assertSame(root.get("bbbb\\"), root.get("aaaa\\")); + } catch (Exception e) { + fail("should not fail !!!"); + } + } +} From bc35d72d6f292a16fd574c74e54a6bf8ed9c13b8 Mon Sep 17 00:00:00 2001 From: wenshao Date: Sun, 31 May 2020 22:07:35 +0800 Subject: [PATCH 3/3] add testcase for #3206 --- .../json/bvt/issue_3200/Issue3206.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/test/java/com/alibaba/json/bvt/issue_3200/Issue3206.java diff --git a/src/test/java/com/alibaba/json/bvt/issue_3200/Issue3206.java b/src/test/java/com/alibaba/json/bvt/issue_3200/Issue3206.java new file mode 100644 index 0000000000..0e863b1691 --- /dev/null +++ b/src/test/java/com/alibaba/json/bvt/issue_3200/Issue3206.java @@ -0,0 +1,29 @@ +package com.alibaba.json.bvt.issue_3200; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.annotation.JSONField; +import com.alibaba.fastjson.serializer.NameFilter; +import junit.framework.TestCase; + +public class Issue3206 extends TestCase { + public void test_for_issue() throws Exception { + VO vo = new VO(); + vo.date = new java.util.Date(1590819204293L); + + + assertEquals(JSON.toJSONString(vo), "{\"date\":\"2020-05-30\"}"); + + String str = JSON.toJSONString(vo, new NameFilter() { + @Override + public String process(Object object, String name, Object value) { + return name; + } + }); + assertEquals(str, "{\"date\":\"2020-05-30\"}"); + } + + public static class VO { + @JSONField(format="yyyy-MM-dd") + public java.util.Date date; + } +}