Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
bug fixed for issue 502, support chinese getter/setter
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Feb 28, 2016
1 parent e8f8f25 commit 965d015
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ASMDeserializerFactory implements Opcodes {

private final ASMClassLoader classLoader;

private final Map<String, Class> classMap = new HashMap<String, Class>();
private final Map<String, Class<?>> classMap = new HashMap<String, Class<?>>();

private final AtomicLong seed = new AtomicLong();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/alibaba/fastjson/util/TypeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,9 @@ public static List<FieldInfo> computeGetters(Class<?> clazz, Map<String, String>
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 {
Expand Down Expand Up @@ -1257,7 +1259,7 @@ public static List<FieldInfo> computeGetters(Class<?> clazz, Map<String, String>

return fieldInfoList;
}

public static JSONField getSupperMethodAnnotation(Class<?> clazz, Method method) {
for (Class<?> interfaceClass : clazz.getInterfaces()) {
for (Method interfaceMethod : interfaceClass.getMethods()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> head() {
List<String> h = new ArrayList<String>();

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.时间 = 时间;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());

}
Expand All @@ -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());
}
}

0 comments on commit 965d015

Please sign in to comment.