mirror of
https://github.com/alibaba/fastjson.git
synced 2026-10-22 17:38:29 +08:00
improve json parser
This commit is contained in:
@@ -88,22 +88,14 @@ public final class CharTypes {
|
||||
specicalFlags_singleQuotes['\u000B'] = 4; // 11
|
||||
specicalFlags_singleQuotes['\f'] = 1; // 12
|
||||
specicalFlags_singleQuotes['\r'] = 1; // 13
|
||||
specicalFlags_singleQuotes['\u000E'] = 4; // 14
|
||||
specicalFlags_singleQuotes['\u000F'] = 4; // 15
|
||||
specicalFlags_singleQuotes['\u0010'] = 4; // 16
|
||||
specicalFlags_singleQuotes['\u0011'] = 4; // 17
|
||||
specicalFlags_singleQuotes['\u0012'] = 4; // 18
|
||||
specicalFlags_singleQuotes['\u0013'] = 4; // 19
|
||||
specicalFlags_singleQuotes['\u0014'] = 4; // 20
|
||||
specicalFlags_singleQuotes['\u0015'] = 4; // 21
|
||||
specicalFlags_singleQuotes['\u0016'] = 4; // 22
|
||||
specicalFlags_singleQuotes['\u0017'] = 4; // 23
|
||||
specicalFlags_singleQuotes['\u0018'] = 4; // 24
|
||||
specicalFlags_singleQuotes['\u0019'] = 4; // 25
|
||||
specicalFlags_singleQuotes['\u0020'] = 4; // 26
|
||||
specicalFlags_singleQuotes['\\'] = 1;
|
||||
specicalFlags_singleQuotes['\''] = 1;
|
||||
|
||||
for (int i = 0x0E; i <= 0x1F; ++i) {
|
||||
specicalFlags_doubleQuotes[i] = 4;
|
||||
specicalFlags_singleQuotes[i] = 4;
|
||||
}
|
||||
|
||||
for (int i = 0x7F; i <= 0xA0; ++i) {
|
||||
specicalFlags_doubleQuotes[i] = 4;
|
||||
specicalFlags_singleQuotes[i] = 4;
|
||||
|
||||
@@ -177,7 +177,7 @@ public class JavaBeanDeserializer implements ObjectDeserializer {
|
||||
}
|
||||
|
||||
ParseContext context = parser.getContext();
|
||||
if (object != null) {
|
||||
if (object != null && context != null) {
|
||||
context = context.getParentContext();
|
||||
}
|
||||
ParseContext childContext = null;
|
||||
|
||||
@@ -1403,7 +1403,7 @@ public final class SerializeWriter extends Writer {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ch <= 13 || ch == '\\' || ch == '"') {
|
||||
if (ch <= 0x1F || ch == '\\' || ch == '"') {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.alibaba.json.bvt.bug;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public class Bug_for_zhongyin extends TestCase {
|
||||
|
||||
public void test_entity() throws Exception {
|
||||
for (char c = '\u0000'; c < '\u0020'; c++) {
|
||||
String s = String.valueOf(c) + "entity";
|
||||
String jsons = JSON.toJSONString(new VO(s));
|
||||
System.out.println(jsons);
|
||||
VO v = JSON.parseObject(jsons, VO.class);
|
||||
Assert.assertEquals(s, v.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void test_map() throws Exception {
|
||||
for (char c = '\u0000'; c < '\u0020'; c++) {
|
||||
String s = String.valueOf(c) + "map";
|
||||
String jsons = JSON.toJSONString(Collections.singletonMap("value", s));
|
||||
System.out.println(jsons);
|
||||
|
||||
JSONObject o = JSON.parseObject(jsons);
|
||||
Assert.assertEquals(s, o.getString("value"));
|
||||
}
|
||||
}
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String hex = "41544D20E58F96E78EB0EFBC8DE993B6E88194E5908CE59F8E1A20E4BD9BE5B1B1E5B882E7A685E59F8EE58CBAE7A596E5BA99E8B7AF201A33331A20E58FB7E799BEE88AB1E5B9BFE59CBAE9A696E5B182201A";
|
||||
String result = getHexStr(hex);
|
||||
|
||||
Map <String , Object>map = new HashMap<String, Object>();
|
||||
map.put("aaa" , result);
|
||||
String stringV = JSON.toJSONString(map);
|
||||
System.out.println(stringV);
|
||||
JSONObject o = JSON.parseObject(stringV);
|
||||
System.out.println(o.getString("aaa"));
|
||||
|
||||
}
|
||||
|
||||
private String getHexStr(String hex) throws UnsupportedEncodingException {
|
||||
byte []bytes = new byte[hex.length() / 2];
|
||||
for(int i = 0 ; i < bytes.length ; i++) {
|
||||
String v = hex.substring(i * 2 , i * 2 + 2);
|
||||
bytes[i] = (byte)Integer.parseInt(v , 16);
|
||||
}
|
||||
String str = new String(bytes , "UTF-8");
|
||||
System.out.println(str);
|
||||
return str;
|
||||
}
|
||||
|
||||
public static class VO {
|
||||
|
||||
private String name;
|
||||
|
||||
public VO(){
|
||||
|
||||
}
|
||||
|
||||
public VO(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user