diff --git a/src/main/java/com/alibaba/fastjson/parser/deserializer/ASMDeserializerFactory.java b/src/main/java/com/alibaba/fastjson/parser/deserializer/ASMDeserializerFactory.java index 110222ffbc..6d78c18c7c 100755 --- a/src/main/java/com/alibaba/fastjson/parser/deserializer/ASMDeserializerFactory.java +++ b/src/main/java/com/alibaba/fastjson/parser/deserializer/ASMDeserializerFactory.java @@ -41,7 +41,7 @@ public class ASMDeserializerFactory implements Opcodes { private final ASMClassLoader classLoader; - private final Map classMap = new HashMap(); + private final Map> classMap = new HashMap>(); private final AtomicLong seed = new AtomicLong(); diff --git a/src/main/java/com/alibaba/fastjson/util/DeserializeBeanInfo.java b/src/main/java/com/alibaba/fastjson/util/DeserializeBeanInfo.java index 0d2829ee5c..56723228af 100755 --- a/src/main/java/com/alibaba/fastjson/util/DeserializeBeanInfo.java +++ b/src/main/java/com/alibaba/fastjson/util/DeserializeBeanInfo.java @@ -363,7 +363,9 @@ public static DeserializeBeanInfo computeSetters(Class clazz, Type type) { char c3 = methodName.charAt(3); String propertyName; - if (Character.isUpperCase(c3)) { + if (Character.isUpperCase(c3) // + || c3 > 512 // for unicode method name + ) { if (TypeUtils.compatibleWithJavaBean) { propertyName = TypeUtils.decapitalize(methodName.substring(3)); } else { diff --git a/src/main/java/com/alibaba/fastjson/util/TypeUtils.java b/src/main/java/com/alibaba/fastjson/util/TypeUtils.java index b9db7cefbc..ee7e1ad965 100755 --- a/src/main/java/com/alibaba/fastjson/util/TypeUtils.java +++ b/src/main/java/com/alibaba/fastjson/util/TypeUtils.java @@ -1050,7 +1050,9 @@ public static List computeGetters(Class clazz, Map char c3 = methodName.charAt(3); String propertyName; - if (Character.isUpperCase(c3)) { + if (Character.isUpperCase(c3) // + || c3 > 512 // for unicode method name + ) { if (compatibleWithJavaBean) { propertyName = decapitalize(methodName.substring(3)); } else { @@ -1257,7 +1259,7 @@ public static List computeGetters(Class clazz, Map return fieldInfoList; } - + public static JSONField getSupperMethodAnnotation(Class clazz, Method method) { for (Class interfaceClass : clazz.getInterfaces()) { for (Method interfaceMethod : interfaceClass.getMethods()) { diff --git a/src/test/java/com/alibaba/json/bvt/bug/Bug_for_BlankRain_Issue_502.java b/src/test/java/com/alibaba/json/bvt/bug/Bug_for_BlankRain_Issue_502.java new file mode 100644 index 0000000000..675e6e3d61 --- /dev/null +++ b/src/test/java/com/alibaba/json/bvt/bug/Bug_for_BlankRain_Issue_502.java @@ -0,0 +1,107 @@ +package com.alibaba.json.bvt.bug; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; + +import com.alibaba.fastjson.JSON; + +import junit.framework.TestCase; + +public class Bug_for_BlankRain_Issue_502 extends TestCase { + + public void test_for_issue() throws Exception { + People a1 = new People(); + a1.set姓名("A"); + a1.set类型("B"); + a1.set状态("C"); + a1.set满意度("D"); + a1.set统计("E"); + a1.set时间("F"); + + String text = JSON.toJSONString(a1); + Assert.assertEquals("{\"姓名\":\"A\",\"时间\":\"F\",\"满意度\":\"D\",\"状态\":\"C\",\"类型\":\"B\",\"统计\":\"E\"}", text); + System.out.println(text); + + People a2 = JSON.parseObject(text, People.class); + Assert.assertEquals(a1.get姓名(), a2.get姓名()); + Assert.assertEquals(a1.get类型(), a2.get类型()); + Assert.assertEquals(a1.get状态(), a2.get状态()); + Assert.assertEquals(a1.get满意度(), a2.get满意度()); + Assert.assertEquals(a1.get统计(), a2.get统计()); + Assert.assertEquals(a1.get时间(), a2.get时间()); + } + + public static class People { + + private String 姓名; + private String 类型; + private String 状态; + private String 满意度; + private String 统计; + private String 时间; + + static List head() { + List h = new ArrayList(); + + h.add("姓名"); + h.add("类型"); + h.add("状态"); + h.add("满意度"); + h.add("统计"); + h.add("时间"); + return h; + } + + public String get姓名() { + return 姓名; + } + + public void set姓名(String 姓名) { + this.姓名 = 姓名; + } + + public String get类型() { + return 类型; + } + + public void set类型(String 类型) { + this.类型 = 类型; + } + + public String get状态() { + return 状态; + } + + public void set状态(String 状态) { + this.状态 = 状态; + } + + public String get满意度() { + return 满意度; + } + + public void set满意度(String 满意度) { + this.满意度 = 满意度; + } + + public String get统计() { + return 统计; + } + + public void set统计(String 统计) { + this.统计 = 统计; + } + + public String get时间() { + return 时间; + } + + public void set时间(String 时间) { + this.时间 = 时间; + } + + } + +} diff --git a/src/test/java/com/alibaba/json/bvt/parser/JSONLexerAllowCommentTest.java b/src/test/java/com/alibaba/json/bvt/parser/JSONLexerAllowCommentTest.java index e9b5418ff3..2505a71fba 100644 --- a/src/test/java/com/alibaba/json/bvt/parser/JSONLexerAllowCommentTest.java +++ b/src/test/java/com/alibaba/json/bvt/parser/JSONLexerAllowCommentTest.java @@ -18,14 +18,15 @@ public class JSONLexerAllowCommentTest extends TestCase { public void test_0() throws Exception { String jsonWithComment = "{ /*tes****\n\r\n*t*/\"a\":1 /*****test88888*****/ /*test*/ , /*test*/ //test\n //est\n \"b\":2}"; - JSONObject object = JSON.parseObject(jsonWithComment, Feature.AllowComment); + JSONObject object = JSON.parseObject(jsonWithComment, Feature.AllowComment, Feature.OrderedField); System.out.println(object.toJSONString()); - Assert.assertEquals("{\"b\":2,\"a\":1}",object.toJSONString()); + Assert.assertEquals("{\"a\":1,\"b\":2}",object.toJSONString()); DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner(jsonWithComment, - Feature.AllowComment.getMask())); + Feature.AllowComment.getMask() | Feature.OrderedField.getMask())); + JSONObject object1 = parser.parseObject(); - Assert.assertEquals("{\"b\":2,\"a\":1}",object1.toJSONString()); + Assert.assertEquals("{\"a\":1,\"b\":2}",object1.toJSONString()); System.out.println(object1.toJSONString()); } @@ -37,12 +38,12 @@ public void test_1() throws IOException { String text = IOUtils.toString(is); is.close(); - JSONObject object = JSON.parseObject(text, Feature.AllowComment); + JSONObject object = JSON.parseObject(text, Feature.AllowComment, Feature.OrderedField); System.out.println(object.toJSONString()); Assert .assertEquals( - "{\"hello\":\"asafsadf\",\"test\":1,\"object\":{\"teset\":1000},\"array\":[\"10000sfsaf\",100,{\"nihao\":{\"test\":\"sdfasdf\"}}]}", + "{\"hello\":\"asafsadf\",\"test\":1,\"array\":[\"10000sfsaf\",100,{\"nihao\":{\"test\":\"sdfasdf\"}}],\"object\":{\"teset\":1000}}", object.toJSONString()); } }