100+ results for 'com.alibaba. fast json'
Not the results you expected?
LexerTest.java (https://github.com/alibaba/fastjson.git) Java · 312 lines
22 import junit.framework.TestCase;
24 import com.alibaba.fastjson.JSON;
25 import com.alibaba.fastjson.JSONArray;
26 import com.alibaba.fastjson.parser.JSONScanner;
27 import com.alibaba.fastjson.parser.JSONToken;
29 public class LexerTest extends TestCase {
218 }
219 {
220 JSONScanner lexer = new JSONScanner("nuul");
221 lexer.nextToken();
222 Assert.assertEquals(JSONToken.IDENTIFIER, lexer.token());
281 public void test_big_integer_3() throws Exception {
282 String text = "9223372036854775809";
283 JSONScanner lexer = new JSONScanner(text);
284 lexer.nextToken();
285 Assert.assertEquals(new BigInteger(text), lexer.integerValue());
SerializeWriterTest.java (https://github.com/alibaba/fastjson.git) Java · 229 lines
TypeUtilsTest.java (https://github.com/flydream/fastjson.git) Java · 418 lines
15 import org.junit.Assert;
17 import com.alibaba.fastjson.JSON;
18 import com.alibaba.fastjson.JSONException;
19 import com.alibaba.fastjson.JSONObject;
20 import com.alibaba.fastjson.parser.ParserConfig;
71 public void test_cast_to_short() throws Exception {
72 JSONObject json = new JSONObject();
73 json.put("id", 1);
221 long millis = System.currentTimeMillis();
223 JSONObject json = new JSONObject();
224 json.put("date", Long.toString(millis));
JSONScannerTest.java (https://github.com/alibaba/fastjson.git) Java · 561 lines
48 // Act
49 Class<?> c = Reflector.forName("com.alibaba.fastjson.parser.JSONScanner");
50 Method m = c.getDeclaredMethod("checkDate", Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("int"), Reflector.forName("int"));
51 m.setAccessible(true);
258 // Act
259 Class<?> c = Reflector.forName("com.alibaba.fastjson.parser.JSONScanner");
260 Method m = c.getDeclaredMethod("checkDate", Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("int"), Reflector.forName("int"));
261 m.setAccessible(true);
510 // Act
511 Class<?> c = Reflector.forName("com.alibaba.fastjson.parser.JSONScanner");
512 Method m = c.getDeclaredMethod("checkDate", Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("char"), Reflector.forName("int"), Reflector.forName("int"));
513 m.setAccessible(true);
RyuDoubleTest.java (https://github.com/alibaba/fastjson.git) Java · 460 lines
AEHuangliang2Test.java (https://github.com/alibaba/fastjson.git) Java · 395 lines
1 package com.alibaba.json.bvt.parser;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject;
5 import com.alibaba.fastjson.parser.DefaultJSONParser;
6 import com.alibaba.fastjson.parser.JSONToken;
7 import com.alibaba.fastjson.parser.ParserConfig;
8 import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
386 MockResult data = JSON.parseObject(floordata, MockResult.class);
387 String mockResultJson = JSON.toJSONString(data.mockResult);
388 NetResponse response = JSON.parseObject(mockResultJson, NetResponse.class);
390 String bodyJson = JSON.toJSONString(response.body);
391 System.out.println(bodyJson);
Issue2779.java (https://github.com/alibaba/fastjson.git) Java · 2221 lines
Bug_for_yangzhou.java (https://github.com/alibaba/fastjson.git) Java · 1143 lines
1 package com.alibaba.json.bvt.bug;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject;
15 System.out.println(test);
16 CabinetAuthCodeParam cabinetAuthCodeParam = JSONObject.toJavaObject(JSON.parseObject(test), CabinetAuthCodeParam.class);
17 System.out.println(JSON.toJSONString(cabinetAuthCodeParam));
18 final String jsonString = JSON.toJSONString(cabinetAuthCodeParam);
19 assertEquals("{\"distinct\":false,\"oredCriteria\":[{\"allCriteria\":[{\"listValue\":false,\"noValue\":false,\"condition\":\"area_id =\",\"betweenValue\":false,\"singleValue\":true,\"value\":917477670000000000},{\"listValue\":false,\"noValue\":false,\"condition\":\"cabinet_id =\",\"betweenValue\":false,\"singleValue\":true,\"value\":500036},{\"listValue\":false,\"noValue\":false,\"condition\":\"status =\",\"betweenValue\":false,\"singleValue\":true,\"value\":0}],\"criteria\":[{\"$ref\":\"$.oredCriteria[0].allCriteria[0]\"},{\"$ref\":\"$.oredCriteria[0].allCriteria[1]\"},{\"$ref\":\"$.oredCriteria[0].allCriteria[2]\"}],\"valid\":true}],\"page\":true,\"pageIndex\":0,\"pageSize\":1,\"pageStart\":1}", jsonString);
20 // CabinetAuthCodeRecordParam cabinetAuthCodeRecordParam = JSONObject.toJavaObject(JSON.parseObject(jsonString), CabinetAuthCodeRecordParam.class);
21 // System.out.println(JSON.toJSONString(cabinetAuthCodeRecordParam));
Huge_300_ClassTest.java (https://github.com/alibaba/fastjson.git) Java · 2473 lines
Huge_200_ClassTest.java (https://github.com/alibaba/fastjson.git) Java · 1826 lines
JSONScannerTest.java (https://github.com/alibaba/fastjson.git) Java · 1473 lines
823 // Arrange
824 JSONScanner objectUnderTest = ((JSONScanner)Reflector.getInstance("com.alibaba.fastjson.parser.JSONScanner"));
825 objectUnderTest.hasSpecial = false;
826 objectUnderTest.token = 0;
920 // Arrange
921 JSONScanner objectUnderTest = ((JSONScanner)Reflector.getInstance("com.alibaba.fastjson.parser.JSONScanner"));
922 objectUnderTest.hasSpecial = false;
923 objectUnderTest.token = 0;
967 // Arrange
968 JSONScanner objectUnderTest = ((JSONScanner)Reflector.getInstance("com.alibaba.fastjson.parser.JSONScanner"));
969 objectUnderTest.hasSpecial = false;
970 objectUnderTest.token = 0;
LargeJavaBean.java (https://github.com/alibaba/fastjson.git) Java · 1431 lines
1 package com.alibaba.fastjson.deserializer.issues3796.bean;
3 import com.alibaba.fastjson.annotation.JSONField;
5 import java.util.List;
8 public static final String testName = "testName";
10 @JSONField(name = "_id")
11 private long id;
29 @JSONField(serialize = false)
30 private ObjectA h = new ObjectA();
FieldInfo.java (https://github.com/alibaba/fastjson.git) Java · 592 lines
1 package com.alibaba.fastjson.util;
3 import java.lang.annotation.Annotation;
17 import com.alibaba.fastjson.TypeReference;
18 import com.alibaba.fastjson.annotation.JSONField;
20 public class FieldInfo implements Comparable<FieldInfo> {
177 format = null;
178 }
179 jsonDirect = annotation.jsonDirect();
180 unwrapped = annotation.unwrapped();
181 alternateNames = annotation.alternateNames();
220 }
221 this.getOnly = getOnly;
222 this.jsonDirect = jsonDirect && fieldClass == String.class;
224 if (clazz != null && fieldClass == Object.class && fieldType instanceof TypeVariable) {
RateSearchItemDO.java (https://github.com/alibaba/fastjson.git) Java · 641 lines
1 package com.alibaba.json.test.tmall;
3 import com.alibaba.fastjson.annotation.JSONField;
5 /**
589 public void setAppendPicJson(String appendPicJson) {
590 this.appendPicJson = appendPicJson;
591 }
597 public void setMainComponentJson(String mainComponentJson) {
598 this.mainComponentJson = mainComponentJson;
599 }
605 public void setAppendComponentJson(String appendComponentJson) {
606 this.appendComponentJson = appendComponentJson;
607 }
JSONPath_10_contains.java (https://github.com/alibaba/fastjson.git) Java · 66 lines
1 package com.alibaba.json.bvt.path;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONPath;
52 " }\n" +
53 "}";
54 assertTrue(JSONPath.contains(JSON.parseObject(json), "$.queryScene.scene.queryDataSet.dataSet"));
55 assertFalse(JSONPath.contains(JSON.parseObject(json), "$.queryScene.scene.queryDataSet.dataSet.abcd"));
56 assertTrue(JSONPath.contains(JSON.parseObject(json), "$.queryScene.scene.queryDataSet.dataSet.name"));
57 }
62 // String json = "{\"returnObj\":[{\"$ref\":\"$.subInvokes.com\\\\.alipay\\\\.cif\\\\.user\\\\.UserInfoQueryService\\\\@findUserInfosByCardNo\\\\(String[])[0].response[0]\"}]}";
63 // JSON.parseObject(json);
64 // }
Issue3693.java (https://github.com/alibaba/fastjson.git) Java · 109 lines
1 package com.alibaba.json.bvt.issue_3600;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.TypeReference;
5 import com.alibaba.fastjson.annotation.JSONField;
6 import com.alibaba.fastjson.parser.DefaultJSONParser;
7 import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
8 import com.alibaba.fastjson.serializer.JSONSerializer;
9 import com.alibaba.fastjson.serializer.ObjectSerializer;
16 public void test_for_issue() throws Exception {
17 Model<ModelProperties> model = new Model<ModelProperties>("hello 世界", new ModelProperties("红色", 66));
18 String json = JSON.toJSONString(model);
19 assertEquals("{\"name\":\"hello 世界\",\"properties\":\"{\\\"color\\\":\\\"红色\\\",\\\"size\\\":66}\"}", json);
JSONValidator.java (https://github.com/alibaba/fastjson.git) Java · 617 lines
1 package com.alibaba.fastjson;
3 import java.io.Closeable;
20 protected boolean supportMultiValue = false;
22 public static JSONValidator fromUtf8(byte[] jsonBytes) {
23 return new UTF8Validator(jsonBytes);
28 }
30 public static JSONValidator from(String jsonStr) {
31 return new UTF16Validator(jsonStr);
40 }
42 public JSONValidator setSupportMultiValue(boolean supportMultiValue) {
43 this.supportMultiValue = supportMultiValue;
44 return this;
Base64.java (https://github.com/alibaba/fastjson.git) Java · 210 lines
1 package com.alibaba.fastjson.util;
3 import java.util.Arrays;
22 /**
23 * Decodes a BASE64 encoded char array that is known to be resonably well formatted. The method is about twice as
24 * fast as #decode(char[]). The preconditions are:<br>
25 * + The array must have a line length of 76 chars OR no line separators at all (one line).<br>
26 * + Line separator must be "\r\n", as specified in RFC 2045 + The array must not contain illegal characters within
31 * @return The decoded array of bytes. May be of length 0.
32 */
33 public static byte[] decodeFast(char[] chars, int offset, int charsLen) {
34 // Check special case
35 if (charsLen == 0) {
86 }
88 public static byte[] decodeFast(String chars, int offset, int charsLen) {
89 // Check special case
90 if (charsLen == 0) {
JSONPath_field_access_filter_in_int.java (https://github.com/alibaba/fastjson.git) Java · 151 lines
1 package com.alibaba.json.bvt.path;
3 import java.util.ArrayList;
8 import org.junit.Assert;
10 import com.alibaba.fastjson.JSONPath;
12 public class JSONPath_field_access_filter_in_int extends TestCase {
14 public void test_list_in() throws Exception {
15 JSONPath path = new JSONPath("[id in (1001)]");
17 List<Entity> entities = new ArrayList<Entity>();
28 public void test_list_not_in() throws Exception {
29 JSONPath path = new JSONPath("[id not in (1001)]");
31 List<Entity> entities = new ArrayList<Entity>();
Bug_for_lingzhi.java (https://github.com/alibaba/fastjson.git) Java · 269 lines
1 package com.alibaba.json.bvt.parser.bug;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.TypeReference;
5 import com.alibaba.fastjson.serializer.SerializerFeature;
6 import junit.framework.TestCase;
49 "]";
51 // String pstr = JSON.toJSONString(JSON.parse(str), SerializerFeature.PrettyFormat);
52 // System.out.println(pstr);
54 JSON.parseObject(str, new TypeReference<List<EcsTransitionDisplayedMsgConfig>>(){});
55 }
Issue3065.java (https://github.com/alibaba/fastjson.git) Java · 150 lines
JSONUtil.java (https://bitbucket.org/icosplays/sensei.git) Java · 1092 lines
89 if (object == null)
90 {
91 com.alibaba.fastjson.JSONArray array = new com.alibaba.fastjson.JSONArray();
92 array.add(value);
93 _inner.put(key, array);
99 else
100 {
101 com.alibaba.fastjson.JSONArray array = new com.alibaba.fastjson.JSONArray();
102 array.add(object);
103 array.add(value);
124 if (object == null)
125 {
126 com.alibaba.fastjson.JSONArray array = new com.alibaba.fastjson.JSONArray();
127 array.add(value);
128 _inner.put(key, array);
JSONScannerTest_ISO8601.java (https://github.com/alibaba/fastjson.git) Java · 128 lines
1 package com.alibaba.json.bvt.parser;
3 import org.junit.Assert;
6 import com.alibaba.fastjson.parser.Feature;
7 import com.alibaba.fastjson.parser.JSONScanner;
8 import com.alibaba.fastjson.parser.JSONToken;
10 public class JSONScannerTest_ISO8601 extends TestCase {
12 public void test_0() throws Exception {
109 public void test_2() throws Exception {
110 JSONScanner lexer = new JSONScanner("2000-02-10T00:00:00.000");
111 lexer.config(Feature.AllowISO8601DateFormat, true);
112 Assert.assertEquals(true, lexer.scanISO8601DateIfMatch());
ClobSerializerTest.java (https://github.com/alibaba/fastjson.git) Java · 144 lines
1 package com.alibaba.json.bvt.serializer;
3 import java.io.InputStream;
13 import org.junit.Assert;
15 import com.alibaba.fastjson.JSON;
16 import com.alibaba.fastjson.serializer.SerializerFeature;
19 public void test_clob() throws Exception {
20 Assert.assertEquals("\"abcdefg中国\"",
21 JSON.toJSONString(new MockClob("abcdefg中国")));
22 }
24 public void test_clob_null() throws Exception {
25 Assert.assertEquals("{\"value\":null}", JSON.toJSONString(new VO(),
26 SerializerFeature.WriteMapNullValue));
27 }
TestForDubbo.java (https://github.com/alibaba/fastjson.git) Java · 83 lines
1 package com.alibaba.json.bvt.dubbo;
3 import java.util.ArrayList;
6 import junit.framework.TestCase;
8 import com.alibaba.fastjson.JSON;
9 import com.alibaba.fastjson.serializer.SerializerFeature;
10 import com.alibaba.json.test.dubbo.FullAddress;
11 import com.alibaba.json.test.dubbo.HelloServiceImpl;
12 import com.alibaba.json.test.dubbo.Person;
13 import com.alibaba.json.test.dubbo.PersonInfo;
14 import com.alibaba.json.test.dubbo.PersonStatus;
15 import com.alibaba.json.test.dubbo.Phone;
16 import com.alibaba.json.test.dubbo.Tiger;
ListStringFieldTest_stream.java (https://github.com/alibaba/fastjson.git) Java · 208 lines
7 import org.junit.Assert;
9 import com.alibaba.fastjson.JSONException;
10 import com.alibaba.fastjson.JSONReader;
11 import com.alibaba.fastjson.TypeReference;
13 import junit.framework.TestCase;
143 public void test_error_nu() throws Exception {
144 String text = "{\"values\":[nu";
145 JSONReader reader = new JSONReader(new StringReader(text));
147 Exception error = null;
182 public void test_error_rbacket() throws Exception {
183 String text = "{\"values\":[null,]";
184 JSONReader reader = new JSONReader(new StringReader(text));
186 Exception error = null;
NumberFieldTest.java (https://github.com/alibaba/fastjson.git) Java · 192 lines
6 import junit.framework.TestCase;
8 import com.alibaba.fastjson.JSON;
9 import com.alibaba.fastjson.serializer.SerializeConfig;
10 import com.alibaba.fastjson.serializer.SerializerFeature;
12 public class NumberFieldTest extends TestCase {
74 mapping.setAsmEnable(true);
76 String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
77 Assert.assertEquals("{\"value\":" + Long.MAX_VALUE + "}", text);
104 mapping.setAsmEnable(true);
106 String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
107 Assert.assertEquals("{\"value\":3.2}", text);
BookEvalTest.java (https://github.com/alibaba/fastjson.git) Java · 105 lines
1 package com.alibaba.json.bvt.path;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject;
5 import com.alibaba.fastjson.JSONPath;
6 import com.alibaba.fastjson.parser.Feature;
42 public void test_4() throws Exception {
43 assertEquals("[8.95,12.99,8.99,22.99,19.95]", JSON.toJSONString(JSONPath.eval(root, "$..price")));
44 }
60 public void test_8() throws Exception {
61 assertEquals("{\"category\":\"fiction\",\"author\":\"Herman Melville\",\"title\":\"Moby Dick\",\"isbn\":\"0-553-21311-3\",\"price\":8.99}"
62 , JSON.toJSONString(JSONPath.eval(root, "$..book[2]")));
63 }
DefaultFieldDeserializer.java (https://github.com/alibaba/fastjson.git) Java · 142 lines
1 package com.alibaba.fastjson.parser.deserializer;
3 import java.io.ByteArrayInputStream;
9 import java.util.zip.GZIPInputStream;
11 import com.alibaba.fastjson.JSONException;
12 import com.alibaba.fastjson.annotation.JSONField;
13 import com.alibaba.fastjson.parser.DefaultJSONParser;
14 import com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask;
15 import com.alibaba.fastjson.parser.JSONToken;
16 import com.alibaba.fastjson.parser.ParseContext;
17 import com.alibaba.fastjson.parser.ParserConfig;
18 import com.alibaba.fastjson.util.FieldInfo;
LocalDateTimeTest5.java (https://github.com/alibaba/fastjson.git) Java · 183 lines
1 package com.alibaba.json.bvt.jdk8;
3 import java.time.Instant;
7 import java.util.TimeZone;
9 import com.alibaba.fastjson.JSON;
11 import junit.framework.TestCase;
86 public void test_for_jp() throws Exception {
87 VO vo = JSON.parseObject("{\"date\":\"2016年5月6日 09:03:16\"}", VO.class);
89 assertEquals(2016, vo.date.getYear());
94 public void test_for_cn() throws Exception {
95 VO vo = JSON.parseObject("{\"date\":\"2016年5月6日 9时3分16秒\"}", VO.class);
97 assertEquals(2016, vo.date.getYear());
Item.java (https://github.com/flydream/fastjson.git) Java · 178 lines
GangliaWriter.java (https://gitlab.com/zhengdingke/htest) Java · 302 lines
14 import org.slf4j.LoggerFactory;
16 import com.alibaba.fastjson.JSON;
17 import com.alibaba.fastjson.annotation.JSONCreator;
57 private String spoofedHostName = null;
59 @JSONCreator
60 public GangliaWriter(String host, Integer port, String addressingMode, Integer ttl, Boolean v31, String units, String slope, Integer tmax, Integer dmax,
61 String groupName) {
222 @Override
223 public String toString() {
224 return JSON.toJSONString(this, true);
225 }
FilterUtils.java (https://bitbucket.org/xiejuntao/xdesktop.git) Java · 297 lines
1 package com.alibaba.fastjson.serializer;
3 import java.util.List;
5 public class FilterUtils {
7 public static Object processValue(JSONSerializer serializer, Object object, String key, Object propertyValue) {
8 List<ValueFilter> valueFilters = serializer.getValueFiltersDirect();
9 if (valueFilters != null) {
16 }
18 public static String processKey(JSONSerializer serializer, Object object, String key, Object propertyValue) {
19 List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
20 if (nameFilters != null) {
27 }
29 public static String processKey(JSONSerializer serializer, Object object, String key, byte intValue) {
30 List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
31 if (nameFilters != null) {
ArrayListStringDeserializer.java (https://bitbucket.org/xiejuntao/xdesktop.git) Java · 109 lines
1 package com.alibaba.fastjson.parser.deserializer;
3 import java.lang.reflect.ParameterizedType;
8 import java.util.Set;
10 import com.alibaba.fastjson.JSONException;
11 import com.alibaba.fastjson.parser.DefaultJSONParser;
12 import com.alibaba.fastjson.parser.Feature;
13 import com.alibaba.fastjson.parser.JSONLexer;
14 import com.alibaba.fastjson.parser.JSONToken;
53 JSONLexer lexer = parser.getLexer();
55 if (lexer.token() == JSONToken.NULL) {
56 lexer.nextToken(JSONToken.COMMA);
66 }
68 lexer.nextToken(JSONToken.LITERAL_STRING);
70 for (;;) {
AppDailyData.java (https://github.com/sohutv/cachecloud.git) Java · 392 lines
JSONObjectTest_readObject.java (https://github.com/alibaba/fastjson.git) Java · 156 lines
1 package com.alibaba.json.bvt;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject;
89 assertEquals(JSONObject.class, obj.getClass());
90 assertEquals(jsonObject.toJSONString(), JSON.toJSONString(obj));
91 }
109 assertEquals(JSONObject.class, obj.getClass());
110 assertEquals(jsonObject.toJSONString(), JSON.toJSONString(obj));
111 }
131 assertEquals(JSONObject.class, obj.getClass());
132 assertEquals(jsonObject.toJSONString(), JSON.toJSONString(obj));
133 }
TypeUtilstTest.java (https://github.com/alibaba/fastjson.git) Java · 233 lines
ASMClassLoader.java (https://github.com/alibaba/fastjson.git) Java · 198 lines
5 import java.util.Map;
7 import com.alibaba.fastjson.JSON;
8 import com.alibaba.fastjson.JSONArray;
9 import com.alibaba.fastjson.JSONAware;
10 import com.alibaba.fastjson.JSONException;
11 import com.alibaba.fastjson.JSONObject;
12 import com.alibaba.fastjson.JSONPath;
13 import com.alibaba.fastjson.JSONPathException;
14 import com.alibaba.fastjson.JSONReader;
22 import com.alibaba.fastjson.parser.JSONReaderScanner;
23 import com.alibaba.fastjson.parser.JSONScanner;
24 import com.alibaba.fastjson.parser.JSONToken;
StackTraceElementDeserializerTest.java (https://github.com/alibaba/fastjson.git) Java · 145 lines
1 package com.alibaba.json.bvt.parser.deser;
3 import org.junit.Assert;
4 import junit.framework.TestCase;
6 import com.alibaba.fastjson.JSON;
7 import com.alibaba.fastjson.JSONException;
45 JSON.parseObject("{\"className\":null,\"methodName\":null,\"fileName\":null,\"lineNumber\":null,\"@type\":\"xxx\"}", StackTraceElement.class);
46 } catch (JSONException ex) {
47 error = ex;
48 }
55 JSON.parseObject("{\"@type\":int}", StackTraceElement.class);
56 } catch (JSONException ex) {
57 error = ex;
58 }
Issue2784.java (https://github.com/alibaba/fastjson.git) Java · 128 lines
1 package com.alibaba.json.bvt.issue_2700;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.annotation.JSONField;
13 Model m = new Model();
14 m.time = java.time.LocalDateTime.now();
15 String str = JSON.toJSONString(m);
16 assertEquals("{\"time\":"
17 + m.time.atZone(JSON.defaultTimeZone.toZoneId()).toInstant().toEpochMilli()
50 Model m = new Model();
51 m.ztime1 = ZonedDateTime.now();
52 String str = JSON.toJSONString(m);
53 assertEquals("{\"ztime1\":"
54 + m.ztime1.toEpochSecond()
89 Model m = new Model();
90 m.date1 = new Date();
91 String str = JSON.toJSONString(m);
92 assertEquals("{\"date1\":"
93 + (m.date1.getTime() / 1000)
Retrofit2ConverterFactory.java (https://github.com/alibaba/fastjson.git) Java · 257 lines
7 import com.alibaba.fastjson.serializer.SerializerFeature;
8 import com.alibaba.fastjson.support.config.FastJsonConfig;
9 import okhttp3.MediaType;
10 import okhttp3.RequestBody;
46 public Retrofit2ConverterFactory(FastJsonConfig fastJsonConfig) {
47 this.fastJsonConfig = fastJsonConfig;
48 }
76 }
78 public Retrofit2ConverterFactory setFastJsonConfig(FastJsonConfig fastJsonConfig) {
79 this.fastJsonConfig = fastJsonConfig;
241 public RequestBody convert(T value) throws IOException {
242 try {
243 byte[] content = JSON.toJSONBytesWithFastJsonConfig(fastJsonConfig.getCharset()
244 , value
245 , fastJsonConfig.getSerializeConfig()
Bug_for_sunai.java (https://github.com/alibaba/fastjson.git) Java · 125 lines
1 package com.alibaba.json.bvt.bug;
3 import java.util.List;
5 import org.junit.Assert;
7 import com.alibaba.fastjson.JSON;
9 import junit.framework.TestCase;
14 MultiLingual ml = JSON.parseObject(text, MultiLingual.class);
15 String text2 = JSON.toJSONString(ml);
16 System.out.println(text2);
17 Assert.assertEquals(text, text2);
JSONReader.java (https://github.com/alibaba/fastjson.git) Java · 346 lines
1 package com.alibaba.fastjson;
3 import static com.alibaba.fastjson.JSONStreamContext.ArrayValue;
4 import static com.alibaba.fastjson.JSONStreamContext.PropertyKey;
5 import static com.alibaba.fastjson.JSONStreamContext.PropertyValue;
6 import static com.alibaba.fastjson.JSONStreamContext.StartArray;
7 import static com.alibaba.fastjson.JSONStreamContext.StartObject;
9 import java.io.Closeable;
14 import java.util.TimeZone;
16 import com.alibaba.fastjson.parser.DefaultJSONParser;
17 import com.alibaba.fastjson.parser.Feature;
InboxService.java (https://gitlab.com/Mr.Tomato/linbox_server) Java · 236 lines
1 package com.linbox.im.server.service.impl;
3 import com.alibaba.fastjson.JSON;
4 import com.linbox.im.message.UnreadMsg;
5 import com.linbox.im.server.constant.RedisKey;
48 String redisKey = RedisKey.getInboxKey(id);
49 String json = JSON.toJSONString(msg);
51 if (StringUtils.isBlank(json)) {
76 if (newUnreadMsg == null) {
77 logger.error("The message is stale. Message in redis: {}. Message received: {}", JSON.toJSONString(oldUnreadMsg), JSON.toJSONString(msg));
78 return;
79 }
DeserializeBeanInfo.java (https://github.com/flydream/fastjson.git) Java · 287 lines
1 package com.alibaba.fastjson.util;
3 import java.lang.annotation.Annotation;
10 import java.util.List;
12 import com.alibaba.fastjson.JSONException;
13 import com.alibaba.fastjson.annotation.JSONCreator;
14 import com.alibaba.fastjson.annotation.JSONField;
16 public class DeserializeBeanInfo {
157 }
159 JSONField annotation = method.getAnnotation(JSONField.class);
161 if (annotation != null) {
JacksonObjectInput.java (https://gitlab.com/sxyseo/dubbox) Java · 178 lines
16 package com.alibaba.dubbo.common.serialize.support.json;
18 import com.alibaba.dubbo.common.json.Jackson;
19 import com.alibaba.dubbo.common.serialize.ObjectInput;
20 import com.alibaba.dubbo.common.utils.ReflectUtils;
21 import com.fasterxml.jackson.databind.ObjectMapper;
30 /**
31 * JsonObjectInput
32 *
33 * @author dylan
134 // if (json.startsWith("{")) {
135 // return JSON.parse(json, Map.class);
136 // } else {
137 // json = "{\"value\":" + json + "}";
Issue408.java (https://github.com/alibaba/fastjson.git) Java · 281 lines
1 package com.alibaba.json.bvt.bug;
3 import com.alibaba.fastjson.JSONReader;
4 import com.alibaba.fastjson.parser.Feature;
18 inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
20 com.alibaba.fastjson.parser.ParserConfig.global.addAccept("com.alibaba.json.bvt.bug.Issue408.");
21 }
29 public void test_for_issue() throws Exception {
31 JSONReader jsonReader = new JSONReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
32 jsonReader.config(Feature.AllowArbitraryCommas, true);
33 jsonReader.config(Feature.IgnoreNotMatch, true);
34 jsonReader.config(Feature.SortFeidFastMatch, false);
35 jsonReader.config(Feature.DisableCircularReferenceDetect, true);
JobSchedule.java (https://github.com/aliyun/aliyun-log-java-sdk.git) Java · 335 lines
4 import com.alibaba.fastjson.annotation.JSONField;
5 import com.aliyun.openservices.log.util.JsonUtils;
6 import com.alibaba.fastjson.JSONObject;
8 import java.io.Serializable;
82 * timeZone eg. +0800
83 */
84 @JSONField
85 private String timeZone;
265 startTime = JsonUtils.readOptionalDate(value, "startTime");
266 completeTime = JsonUtils.readOptionalDate(value, "completeTime");
267 createTime = JsonUtils.readOptionalDate(value, "createTime");
NamingSerTest.java (https://github.com/alibaba/fastjson.git) Java · 90 lines
3 import org.junit.Assert;
5 import com.alibaba.fastjson.JSON;
6 import com.alibaba.fastjson.PropertyNamingStrategy;
7 import com.alibaba.fastjson.parser.ParserConfig;
8 import com.alibaba.fastjson.serializer.SerializeConfig;
10 import junit.framework.TestCase;
18 Model model = new Model();
19 model.personId = 1001;
20 String text = JSON.toJSONString(model, config);
21 Assert.assertEquals("{\"person_id\":1001}", text);
36 Model model = new Model();
37 model.personId = 1001;
38 String text = JSON.toJSONString(model, config);
39 Assert.assertEquals("{\"person-id\":1001}", text);
ListTypeFieldDeserializer.java (https://github.com/virjar/sekiro.git) Java · 255 lines
1 package external.com.alibaba.fastjson.parser;
3 import java.lang.reflect.*;
7 import java.util.Map;
9 import external.com.alibaba.fastjson.JSONArray;
10 import external.com.alibaba.fastjson.JSONException;
11 import external.com.alibaba.fastjson.parser.deserializer.FieldDeserializer;
12 import external.com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
13 import external.com.alibaba.fastjson.util.FieldInfo;
14 import external.com.alibaba.fastjson.util.ParameterizedTypeImpl;
15 import external.com.alibaba.fastjson.util.TypeUtils;
17 class ListTypeFieldDeserializer extends FieldDeserializer {
Find.java (https://github.com/lihang212010/Elasticsearch-ais.git) Java · 991 lines
4 import com.alibaba.fastjson.JSON;
5 import org.springframework.boot.elasticsearch.ais.utils.CollectUtil;
6 import org.springframework.boot.elasticsearch.ais.utils.StringUtils;
40 + " \"term\": {\n"
41 + " \"" + key + "\": {\n"
42 + " \"value\": " + JSON.toJSONString(value) + "\n"
43 + " }\n"
44 + " }\n"
62 + " \"term\": {\n"
63 + " \"" + key + "\": {\n"
64 + " \"value\": " + JSON.toJSONString(value) + ", \n"
65 + " \"boost\": " + boost + "\n"
66 + " }\n"
Bug_for_ascii_0_31.java (https://github.com/alibaba/fastjson.git) Java · 110 lines
1 package com.alibaba.json.bvt.bug;
3 import org.junit.Assert;
4 import junit.framework.TestCase;
6 import com.alibaba.fastjson.JSON;
7 import com.alibaba.fastjson.serializer.SerializerFeature;
15 buf.append(ch);
17 String text = JSON.toJSONString(buf.toString(), SerializerFeature.BrowserCompatible);
19 switch (ch) {
54 vo.setContent(buf.toString());
56 String voText = JSON.toJSONString(vo, SerializerFeature.BrowserCompatible);
58 switch (ch) {
UTF8Decoder.java (https://github.com/flydream/fastjson.git) Java · 215 lines
JSONPath_field_access_filter_compare_string.java (https://github.com/alibaba/fastjson.git) Java · 167 lines
4 import java.util.List;
6 import com.alibaba.fastjson.JSON;
7 import com.alibaba.fastjson.JSONArray;
10 import org.junit.Assert;
12 import com.alibaba.fastjson.JSONPath;
14 public class JSONPath_field_access_filter_compare_string extends TestCase {
16 public void test_list_eq() throws Exception {
17 JSONPath path = new JSONPath("$[?(@.name = 'ljw2083')]");
19 List<Entity> entities = new ArrayList<Entity>();
30 public void test_list_eq_x() throws Exception {
31 JSONPath path = new JSONPath("$[?(name = 'ljw2083')]");
33 List<Entity> entities = new ArrayList<Entity>();
BookExtractTest.java (https://github.com/alibaba/fastjson.git) Java · 103 lines
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject;
5 import com.alibaba.fastjson.JSONPath;
63 public void test_9() throws Exception {
64 assertEquals("{\"category\":\"fiction\",\"author\":\"J. R. R. Tolkien\",\"title\":\"The Lord of the Rings\",\"isbn\":\"0-395-19395-8\",\"price\":22.99}"
65 , JSON.toJSONString(JSONPath.extract(json, "$..book[-1]")));
66 }
68 public void test_10() throws Exception {
69 assertEquals("[{\"category\":\"reference\",\"author\":\"Nigel Rees\",\"title\":\"Sayings of the Century\",\"price\":8.95},{\"category\":\"fiction\",\"author\":\"Evelyn Waugh\",\"title\":\"Sword of Honour\",\"price\":12.99}]"
70 , JSON.toJSONString(JSONPath.extract(json, "$..book[0,1]")));
71 }
98 public void test_16() throws Exception {
99 assertEquals("[{\"category\":\"fiction\",\"author\":\"Herman Melville\",\"title\":\"Moby Dick\",\"isbn\":\"0-553-21311-3\",\"price\":8.99}]"
100 , JSON.toJSONString(JSONPath.extract(json, "$.store.book[?(@.price < 10 && @.category == 'fiction')]")));
101 }
ListStringFieldTest_stream_array.java (https://github.com/alibaba/fastjson.git) Java · 280 lines
7 import org.junit.Assert;
9 import com.alibaba.fastjson.JSONException;
10 import com.alibaba.fastjson.JSONReader;
11 import com.alibaba.fastjson.TypeReference;
12 import com.alibaba.fastjson.annotation.JSONType;
13 import com.alibaba.fastjson.parser.Feature;
20 String text = "[[\"a\",null,\"b\",\"ab\\\\c\\\"a\"]]";
22 JSONReader reader = new JSONReader(new StringReader(text));
23 Model model = reader.readObject(Model.class);
24 Assert.assertEquals(4, model.values.size());
251 public void test_error_3() throws Exception {
252 String text = "{\"model\":[[]}[";
253 JSONReader reader = new JSONReader(new StringReader(text));
Bug_for_cnhans.java (https://github.com/alibaba/fastjson.git) Java · 99 lines
1 package com.alibaba.json.bvt.bug;
3 import java.util.Calendar;
10 import junit.framework.TestCase;
12 import com.alibaba.fastjson.JSON;
13 import com.alibaba.fastjson.JSONObject;
14 import com.alibaba.fastjson.serializer.SerializerFeature;
16 public class Bug_for_cnhans extends TestCase {
24 vo.setCalendar(Calendar.getInstance());
26 String text = JSON.toJSONString(vo);
28 VO vo1 = JSON.parseObject(text, VO.class);
PullOldMsgHandler.java (https://gitlab.com/Mr.Tomato/linbox_server) Java · 179 lines
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject;
5 import com.linbox.im.exceptions.IMConsumerException;
6 import com.linbox.im.exceptions.IMException;
51 try {
52 logger.debug("start handling PullOldMsgRequest: {}", json);
53 MessageWrapper wrapper = JSON.parseObject(json, MessageWrapper.class);
55 PullOldMsgRequest request = JSON.parseObject(((JSONObject)wrapper.content).toJSONString(), PullOldMsgRequest.class);
56 wrapper.content = request;
87 String remoteId = request.remoteId;
88 if (StringUtils.isBlank(remoteId)) {
89 logger.error("Can not find corresponding remote id for PullOldMsgRequest: {}", json);
91 throw new IMException("Cannot find remote id for PullOldMsgRequest: " + json);
CoreConstant.java (https://github.com/alibaba/DataX.git) Java · 189 lines
1 package com.alibaba.datax.core.util.container;
3 import org.apache.commons.lang.StringUtils;
156 public static String DATAX_CONF_PATH = StringUtils.join(new String[] {
157 DATAX_HOME, "conf", "core.json" }, File.separator);
159 public static String DATAX_CONF_LOG_PATH = StringUtils.join(new String[] {
MetricTimerTask.java (https://gitlab.com/zhengdingke/gmonitor) Java · 107 lines
8 import org.slf4j.LoggerFactory;
10 import com.alibaba.fastjson.JSON;
11 import com.google.common.collect.Maps;
12 import com.kingdeehit.bigdata.appmetric.flume.GangliaFlumeClient;
90 // 以json的形式输入flume
91 // log.info(JSON.toJSONString(info, true));
92 client.sendDataToFlume(JSON.toJSONString(info));
ProducerImpl.java (https://gitlab.com/tanxinzheng/activemq-api) Java · 125 lines
1 package com.udfex.ucs.amq.api;
3 import com.alibaba.fastjson.JSONObject;
4 import com.udfex.ucs.amq.api.service.ProducerService;
5 import org.apache.activemq.ActiveMQConnectionFactory;
57 logger.debug("Producer MessageListener onMessage : " + message);
58 try {
59 ConsumeResult consumeResult = JSONObject.parseObject(message, ConsumeResult.class);
60 if (ConsumeResult.CONSUME_SUCCESS_CODE == consumeResult.getResultCode()) {
61 if(producerService != null){
Bug_for_dragoon26.java (https://github.com/flydream/fastjson.git) Java · 175 lines
1 package com.alibaba.json.bvt.bug;
3 import java.util.ArrayList;
9 import junit.framework.TestCase;
11 import com.alibaba.fastjson.JSON;
12 import com.alibaba.fastjson.annotation.JSONField;
13 import com.alibaba.fastjson.serializer.SerializerFeature;
15 public class Bug_for_dragoon26 extends TestCase {
67 config.setMonitorItems(items);
69 String text = JSON.toJSONString(message, SerializerFeature.WriteClassName);
70 System.out.println(JSON.toJSONString(message, SerializerFeature.WriteClassName, SerializerFeature.PrettyFormat));
DefaultExtJSONParser_parseArray.java (https://github.com/flydream/fastjson.git) Java · 285 lines
10 import junit.framework.TestCase;
12 import com.alibaba.fastjson.JSONObject;
13 import com.alibaba.fastjson.TypeReference;
14 import com.alibaba.fastjson.parser.DefaultExtJSONParser;
15 import com.alibaba.fastjson.parser.Feature;
16 import com.alibaba.fastjson.parser.JSONToken;
18 public class DefaultExtJSONParser_parseArray extends TestCase {
110 public void test_9() throws Exception {
111 DefaultExtJSONParser parser = new DefaultExtJSONParser("");
112 parser.config(Feature.AllowISO8601DateFormat, true);
113 Object value = parser.parse();
Issue1392.java (https://github.com/alibaba/fastjson.git) Java · 147 lines
4 import com.alibaba.fastjson.serializer.SerializerFeature;
5 import com.alibaba.fastjson.support.config.FastJsonConfig;
6 import com.alibaba.fastjson.support.jaxrs.FastJsonFeature;
81 @Provider
82 static class FastJsonResolver implements ContextResolver<FastJsonConfig> {
84 public FastJsonConfig getContext(Class<?> type) {
86 FastJsonConfig fastJsonConfig = new FastJsonConfig();
88 fastJsonConfig.setSerializerFeatures(
118 @Override
119 protected void configureClient(ClientConfig config) {
120 config.register(FastJsonFeature.class);
121 }
DataTransaction.java (https://github.com/alibaba/fastjson.git) Java · 321 lines
1 package com.alibaba.json.bvtVO;
3 import java.io.Serializable;
7 import java.util.Map;
9 import com.alibaba.fastjson.JSON;
11 /**
283 }
285 public static DataTransaction fromJSON(String jsonString) {
286 return JSON.parseObject(jsonString, DataTransaction.class);
289 public String toJSON() {
290 return JSON.toJSONString(this);
291 }
BeamDDLTest.java (https://github.com/apache/beam.git) Java · 240 lines
23 import static org.junit.Assert.assertNull;
25 import com.alibaba.fastjson.JSONArray;
26 import com.alibaba.fastjson.JSONObject;
44 BeamSqlEnv env = BeamSqlEnv.withTableProvider(tableProvider);
46 JSONObject properties = new JSONObject();
47 JSONArray hello = new JSONArray();
109 BeamSqlEnv env = BeamSqlEnv.withTableProvider(tableProvider);
111 JSONObject properties = new JSONObject();
112 JSONArray hello = new JSONArray();
139 + "LOCATION '/home/admin/person'\n");
140 assertEquals(
141 mockTable("person", "text", "person table", new JSONObject()),
142 tableProvider.getTables().get("person"));
143 }
PropertyFilter_float.java (https://github.com/alibaba/fastjson.git) Java · 149 lines
1 package com.alibaba.json.bvt.serializer.filters;
3 import java.util.HashMap;
7 import junit.framework.TestCase;
9 import com.alibaba.fastjson.serializer.JSONSerializer;
10 import com.alibaba.fastjson.serializer.PropertyFilter;
11 import com.alibaba.fastjson.serializer.SerializeWriter;
13 public class PropertyFilter_float extends TestCase {
23 SerializeWriter out = new SerializeWriter();
24 JSONSerializer serializer = new JSONSerializer(out);
25 serializer.getPropertyFilters().add(filter);
PropertyFilter_double.java (https://github.com/alibaba/fastjson.git) Java · 149 lines
1 package com.alibaba.json.bvt.serializer.filters;
3 import java.util.HashMap;
7 import junit.framework.TestCase;
9 import com.alibaba.fastjson.serializer.JSONSerializer;
10 import com.alibaba.fastjson.serializer.PropertyFilter;
11 import com.alibaba.fastjson.serializer.SerializeWriter;
13 public class PropertyFilter_double extends TestCase {
23 SerializeWriter out = new SerializeWriter();
24 JSONSerializer serializer = new JSONSerializer(out);
25 serializer.getPropertyFilters().add(filter);
PropertyFilter_short.java (https://github.com/alibaba/fastjson.git) Java · 149 lines
1 package com.alibaba.json.bvt.serializer.filters;
3 import java.util.HashMap;
7 import junit.framework.TestCase;
9 import com.alibaba.fastjson.serializer.JSONSerializer;
10 import com.alibaba.fastjson.serializer.PropertyFilter;
11 import com.alibaba.fastjson.serializer.SerializeWriter;
13 public class PropertyFilter_short extends TestCase {
23 SerializeWriter out = new SerializeWriter();
24 JSONSerializer serializer = new JSONSerializer(out);
25 serializer.getPropertyFilters().add(filter);
FastJsonHttpMessageConverterTest.java (https://github.com/alibaba/fastjson.git) Java · 201 lines
23 import com.alibaba.fastjson.serializer.ValueFilter;
24 import com.alibaba.fastjson.support.config.FastJsonConfig;
25 import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
29 @SuppressWarnings("deprecation")
30 public void test_read() throws Exception {
31 FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
32 converter.setCharset(Charset.forName("UTF-8"));
33 Assert.assertEquals(Charset.forName("UTF-8"), converter.getCharset());
93 public void test_1() throws Exception {
95 FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
97 Assert.assertNotNull(converter.getFastJsonConfig());
98 converter.setFastJsonConfig(new FastJsonConfig());
100 converter.canRead(VO.class, MediaType.APPLICATION_JSON_UTF8);
SerializeFilterable.java (https://github.com/alibaba/fastjson.git) Java · 271 lines
1 package com.alibaba.fastjson.serializer;
3 import java.text.DecimalFormat;
5 import java.util.List;
7 import com.alibaba.fastjson.JSON;
9 public abstract class SerializeFilterable {
130 }
132 public boolean applyName(JSONSerializer jsonBeanDeser, //
133 Object object, String key) {
175 }
177 protected String processKey(JSONSerializer jsonBeanDeser, //
178 Object object, //
179 String key, //
JSONArray.java (https://github.com/flydream/fastjson.git) Java · 345 lines
14 * limitations under the License.
15 */
16 package com.alibaba.fastjson;
18 import static com.alibaba.fastjson.util.TypeUtils.castToBigDecimal;
19 import static com.alibaba.fastjson.util.TypeUtils.castToBigInteger;
20 import static com.alibaba.fastjson.util.TypeUtils.castToBoolean;
23 import static com.alibaba.fastjson.util.TypeUtils.castToDouble;
24 import static com.alibaba.fastjson.util.TypeUtils.castToFloat;
25 import static com.alibaba.fastjson.util.TypeUtils.castToInt;
40 import java.util.RandomAccess;
42 import com.alibaba.fastjson.util.TypeUtils;
44 /**
Issue248_orderedField.java (https://github.com/alibaba/fastjson.git) Java · 81 lines
1 package com.alibaba.json.bvt.bug;
3 import junit.framework.TestCase;
7 import com.alibaba.fastjson.JSON;
8 import com.alibaba.fastjson.JSONObject;
9 import com.alibaba.fastjson.parser.Feature;
13 public void test_0() throws Exception {
14 String text = "{\"b\":\"b\",\"d\":\"d\",\"c\":\"c\",\"a\":\"a\"}";
15 JSONObject object = JSON.parseObject(text, Feature.OrderedField);
16 System.out.println(object);
73 object.getJSONArray("list").getJSONObject(3).getJSONObject("map").keySet().toArray()[0]);
74 Assert.assertEquals("k3",
75 object.getJSONArray("list").getJSONObject(3).getJSONObject("map").keySet().toArray()[1]);
76 Assert.assertEquals("k2",
77 object.getJSONArray("list").getJSONObject(3).getJSONObject("map").keySet().toArray()[2]);
FragmentAnalysis.java (https://github.com/Tencent/GT.git) Java · 419 lines
1 package com.tencent.wstt.gt.datatool.analysis;
3 import com.alibaba.fastjson.JSON;
4 import com.tencent.wstt.gt.datatool.GTRAnalysis;
5 import com.tencent.wstt.gt.datatool.obj.FragmentInfo;
227 long loadTime = getFragmentStartFinishTime(fragmentInfo) - getFragmentStartTime(fragmentInfo);
228 if (loadTime > 300) {
229 System.out.println(JSON.toJSONString(fragmentInfo));
230 boolean isExists = false;
231 for (int h = 0; h < overFragments.size(); h++) {
JSONObjectTest.java (https://github.com/flydream/fastjson.git) Java · 190 lines
25 import junit.framework.TestCase;
27 import com.alibaba.fastjson.JSONObject;
29 public class JSONObjectTest extends TestCase {
76 public void test_getBoolean() throws Exception {
77 JSONObject json = new JSONObject();
78 json.put("A", true);
165 public void test_getObject_null() throws Exception {
166 JSONObject json = new JSONObject();
167 json.put("obj", null);
184 public void test_getObject_map() throws Exception {
185 JSONObject json = new JSONObject();
186 json.put("obj", new HashMap());
SerializeWriterTest_BrowserSecure_5_script_model.java (https://github.com/alibaba/fastjson.git) Java · 89 lines
1 package com.alibaba.json.bvt.serializer;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject;
5 import com.alibaba.fastjson.JSONWriter;
6 import com.alibaba.fastjson.serializer.SerializerFeature;
14 Model object = new Model();
15 object.value = "<script>alert(1);</script>";
16 String text = JSON.toJSONString(object, SerializerFeature.BrowserSecure);
17 // assertEquals("{\"value\":\"<script>alert(1);<\\/script>\"}", text);
18 assertEquals("{\"value\":\"\\u003Cscript\\u003Ealert\\u00281\\u0029;\\u003C/script\\u003E\"}", text);
34 Model object = new Model();
35 object.value = "<script>";
36 String text = JSON.toJSONString(object, SerializerFeature.BrowserSecure);
37 // assertEquals("{\"value\":\"<script>alert(1);<\\/script>\"}", text);
38 assertEquals("{\"value\":\"\\u003Cscript\\u003E\"}", text);
ParserSpecialCharTest.java (https://github.com/alibaba/fastjson.git) Java · 95 lines
1 package com.alibaba.json.bvt.parser;
3 import junit.framework.TestCase;
5 import org.junit.Assert;
7 import com.alibaba.fastjson.JSON;
9 public class ParserSpecialCharTest extends TestCase {
43 public void test_8() throws Exception {
44 Assert.assertEquals("\b", JSON.parseObject("{\"value\":\"\\b\"}", VO.class).getValue());
45 }
47 public void test_9() throws Exception {
48 Assert.assertEquals("\t", JSON.parseObject("{\"value\":\"\\t\"}", VO.class).getValue());
49 }
Issue3448.java (https://github.com/alibaba/fastjson.git) Java · 89 lines
1 package com.alibaba.json.bvt.issue_3300;
3 import java.lang.reflect.ParameterizedType;
8 import java.util.Map;
10 import com.alibaba.fastjson.JSON;
11 import com.alibaba.fastjson.TypeReference;
26 List<Map<String, List<String>>> list = new ArrayList(4);
27 list.add(Collections.singletonMap("key1", Collections.singletonList("item")));
28 String text = JSON.toJSONString(list);
29 System.out.println("text = " + text);
46 List<Map<String, List<String>>> list = new ArrayList(4);
47 list.add(Collections.singletonMap("key1", Collections.singletonList("item")));
48 String text = JSON.toJSONString(list);
49 System.out.println("text = " + text);
ArrayListTypeFieldDeserializer.java (https://github.com/alibaba/fastjson.git) Java · 211 lines
1 package com.alibaba.fastjson.parser.deserializer;
3 import java.lang.reflect.ParameterizedType;
9 import java.util.Map;
11 import com.alibaba.fastjson.JSON;
12 import com.alibaba.fastjson.TypeReference;
13 import com.alibaba.fastjson.parser.DefaultJSONParser;
14 import com.alibaba.fastjson.parser.Feature;
15 import com.alibaba.fastjson.parser.JSONLexer;
16 import com.alibaba.fastjson.parser.JSONToken;
17 import com.alibaba.fastjson.parser.ParseContext;
18 import com.alibaba.fastjson.parser.ParserConfig;
ZkGroupDiscovery.java (https://github.com/happyyangyuan/xian.git) Java · 216 lines
1 package info.xiancloud.zookeeper.service_discovery_new.group;
3 import com.alibaba.fastjson.JSONObject;
4 import com.google.common.cache.CacheBuilder;
5 import com.google.common.cache.CacheLoader;
19 import org.apache.curator.x.discovery.ServiceInstance;
20 import org.apache.curator.x.discovery.ServiceProvider;
21 import org.apache.curator.x.discovery.details.FastjsonServiceDefinitionSerializer;
22 import org.apache.curator.x.discovery.details.InstanceProvider;
80 .basePath(ZkPathManager.getGroupBasePath())
81 .serializer(new ZkServiceInstanceSerializer())
82 .serializer(new FastjsonServiceDefinitionSerializer<>(GroupProxy.class))
83 .client(ZkConnection.client)
84 .build();
Bug_for_dragoon26.java (https://github.com/alibaba/fastjson.git) Java · 179 lines
7 import java.util.Map;
9 import com.alibaba.fastjson.parser.ParserConfig;
10 import junit.framework.TestCase;
12 import com.alibaba.fastjson.JSON;
13 import com.alibaba.fastjson.annotation.JSONField;
14 import com.alibaba.fastjson.serializer.SerializerFeature;
16 public class Bug_for_dragoon26 extends TestCase {
71 config.setMonitorItems(items);
73 String text = JSON.toJSONString(message, SerializerFeature.WriteClassName);
74 System.out.println(JSON.toJSONString(message, SerializerFeature.WriteClassName, SerializerFeature.PrettyFormat));
FieldSerializerTest3.java (https://github.com/alibaba/fastjson.git) Java · 90 lines
4 import junit.framework.TestCase;
6 import com.alibaba.fastjson.JSONException;
7 import com.alibaba.fastjson.annotation.JSONField;
8 import com.alibaba.fastjson.serializer.JSONSerializer;
9 import com.alibaba.fastjson.serializer.NameFilter;
10 import com.alibaba.fastjson.serializer.PropertyFilter;
11 import com.alibaba.fastjson.serializer.SerializeWriter;
12 import com.alibaba.fastjson.serializer.SerializerFeature;
13 import com.alibaba.fastjson.serializer.ValueFilter;
15 public class FieldSerializerTest3 extends TestCase {
51 }
52 });
53 for (com.alibaba.fastjson.serializer.SerializerFeature feature : features) {
54 serializer.config(feature, true);
55 }
DefaultObjectDeserializerTest1.java (https://github.com/flydream/fastjson.git) Java · 118 lines
8 import junit.framework.TestCase;
10 import com.alibaba.fastjson.JSON;
11 import com.alibaba.fastjson.TypeReference;
12 import com.alibaba.fastjson.parser.DefaultExtJSONParser;
13 import com.alibaba.fastjson.parser.ParserConfig;
14 import com.alibaba.fastjson.parser.deserializer.DefaultObjectDeserializer;
16 public class DefaultObjectDeserializerTest1 extends TestCase {
18 public void test_0() throws Exception {
19 String input = "{'map':{}}";
20 DefaultExtJSONParser parser = new DefaultExtJSONParser(input, ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);
22 DefaultObjectDeserializer deser = new DefaultObjectDeserializer();
ListSerializer.java (https://github.com/alibaba/fastjson.git) Java · 148 lines
14 * limitations under the License.
15 */
16 package com.alibaba.fastjson.serializer;
18 import com.alibaba.fastjson.util.TypeUtils;
29 public static final ListSerializer instance = new ListSerializer();
31 public final void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
32 throws IOException {
FilterUtils.java (https://github.com/flydream/fastjson.git) Java · 281 lines
1 package com.alibaba.fastjson.serializer;
3 import java.util.List;
5 public class FilterUtils {
6 public static Object processValue(JSONSerializer serializer, Object object, String key, Object propertyValue) {
7 List<ValueFilter> valueFilters = serializer.getValueFiltersDirect();
8 if (valueFilters != null) {
15 }
17 public static String processKey(JSONSerializer serializer, Object object, String key, Object propertyValue) {
18 List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
19 if (nameFilters != null) {
26 }
28 public static String processKey(JSONSerializer serializer, Object object, String key, byte intValue) {
29 List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
30 if (nameFilters != null) {
JSONPath_size.java (https://github.com/alibaba/fastjson.git) Java · 88 lines
6 import org.junit.Assert;
8 import com.alibaba.fastjson.JSONObject;
9 import com.alibaba.fastjson.JSONPath;
10 import com.alibaba.fastjson.JSONPathException;
11 import com.alibaba.json.bvt.path.JSONPath_between_int.Entity;
30 list.add(new Entity(103, "ljw2083"));
32 JSONObject root = new JSONObject();
33 root.put("values", list);
38 public void test_path_size() throws Exception {
39 JSONPath path = JSONPath.compile("$");
41 Assert.assertEquals(-1, path.size(null));
DeserializeUsingTest.java (https://github.com/alibaba/fastjson.git) Java · 71 lines
1 package com.alibaba.json.bvt.annotation;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.annotation.JSONField;
5 import com.alibaba.fastjson.parser.DefaultJSONParser;
6 import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
19 String jsonStr = "{'subjectList':['CHINESE','MATH']}";
20 Teacher teacher = JSON.parseObject(jsonStr, Teacher.class);
21 assertEquals(SubjectEnum.CHINESE.ordinal(), teacher.getSubjectList().get(0).intValue());
22 assertEquals(SubjectEnum.MATH.ordinal(), teacher.getSubjectList().get(1).intValue());
26 String jsonStr = "{'subjectList':['CHINESE','MATH']}";
28 Teacher teacher = JSON.parseObject(jsonStr).toJavaObject(Teacher.class);
29 assertEquals(SubjectEnum.CHINESE.ordinal(), teacher.getSubjectList().get(0).intValue());
30 assertEquals(SubjectEnum.MATH.ordinal(), teacher.getSubjectList().get(1).intValue());
IntBenchmark.java (https://github.com/alibaba/fastjson.git) Java · 74 lines
1 package com.alibaba.json.test.benchmark.basic;
3 import com.alibaba.fastjson.JSON;
5 import java.util.Random;
28 // model.v5 = new Random().nextInt();
29 //
30 // System.out.println(JSON.toJSONString(model));
41 long start = System.currentTimeMillis();
42 for (int i = 0; i < 1000 * 1000 * 10; ++i) {
43 JSON.parseObject(json, Model.class);
44 }
45 long millis = System.currentTimeMillis() - start;
BeanToArrayTest.java (https://github.com/alibaba/fastjson.git) Java · 73 lines
1 package com.alibaba.json.bvt.parser.array;
3 import java.util.ArrayList;
7 import org.junit.Assert;
9 import com.alibaba.fastjson.JSON;
10 import com.alibaba.fastjson.annotation.JSONType;
11 import com.alibaba.fastjson.parser.Feature;
12 import com.alibaba.fastjson.serializer.SerializerFeature;
18 public void test_beanToArray_parse() throws Exception {
19 String text = "{\"go\":[[\"0\",[true,false],9999999999999,99,\"012345678901234567890123\",\"ftp://gfw.yma.co/x160\",\"xxxx\",\"9876543210123456\",[[\"m\",\"不要开心\",\"http://gfw.meiya.co\",\"123456@gg.com\",\"麻麻\",\"add\",null,\"9876543210123456\"]],null,[\"add\",\"ww\"],999,1234567890123]],\"success\":true}";
20 GR result = JSON.parseObject(text, GR.class);
21 Assert.assertNotNull(result);
22 Assert.assertEquals(1, result.go.size());
StringFieldTest_special_2.java (https://github.com/alibaba/fastjson.git) Java · 72 lines
1 package com.alibaba.json.bvt;
3 import org.junit.Assert;
5 import com.alibaba.fastjson.JSON;
6 import com.alibaba.fastjson.serializer.SerializerFeature;
17 model.name = buf.toString();
19 String text = JSON.toJSONString(model);
21 Model model2 = JSON.parseObject(text, Model.class);
31 model.name = buf.toString();
33 String text = JSON.toJSONString(model, SerializerFeature.BrowserSecure);
34 text = text.replaceAll("<", "<");
35 text = text.replaceAll(">", ">");
JSONObjectTest3.java (https://github.com/alibaba/fastjson.git) Java · 182 lines
1 package com.alibaba.json.bvt;
3 import org.junit.Assert;
4 import junit.framework.TestCase;
6 import com.alibaba.fastjson.JSON;
7 import com.alibaba.fastjson.JSONException;
8 import com.alibaba.fastjson.annotation.JSONField;
10 public class JSONObjectTest3 extends TestCase {
68 Bean bean = JSON.parseObject(text, Bean.class);
70 JSONException error = null;
71 try {
72 bean.is();
JSONSerializerFeatureTest.java (https://github.com/flydream/fastjson.git) Java · 282 lines
9 import junit.framework.TestCase;
11 import com.alibaba.fastjson.serializer.JSONSerializer;
12 import com.alibaba.fastjson.serializer.SerializeWriter;
13 import com.alibaba.fastjson.serializer.SerializerFeature;
15 public class JSONSerializerFeatureTest extends TestCase {
92 public void test_3_s() throws Exception {
93 JSONSerializer serializer = new JSONSerializer(new SerializeWriter());
95 serializer.config(SerializerFeature.QuoteFieldNames, false);
114 public void test_4_s() throws Exception {
115 JSONSerializer serializer = new JSONSerializer(new SerializeWriter());
117 serializer.config(SerializerFeature.QuoteFieldNames, false);
MediaGenDecoder.java (https://github.com/alibaba/fastjson.git) Java · 316 lines
3 import java.lang.reflect.Type;
5 import com.alibaba.fastjson.parser.DefaultJSONParser;
6 import com.alibaba.fastjson.parser.Feature;
7 import com.alibaba.fastjson.parser.JSONLexerBase;
8 import com.alibaba.fastjson.parser.ParseContext;
9 import com.alibaba.fastjson.parser.ParserConfig;
10 import com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer;
11 import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
13 public class MediaGenDecoder extends JavaBeanDeserializer implements ObjectDeserializer {
44 public Object deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
45 JSONLexerBase lexer = (JSONLexerBase) parser.getLexer();
47 if (!lexer.isEnabled(Feature.SortFeidFastMatch)) {
PropertyFilter_double.java (https://github.com/flydream/fastjson.git) Java · 149 lines
1 package com.alibaba.json.bvt.serializer;
3 import java.util.HashMap;
7 import junit.framework.TestCase;
9 import com.alibaba.fastjson.serializer.JSONSerializer;
10 import com.alibaba.fastjson.serializer.PropertyFilter;
11 import com.alibaba.fastjson.serializer.SerializeWriter;
13 public class PropertyFilter_double extends TestCase {
23 SerializeWriter out = new SerializeWriter();
24 JSONSerializer serializer = new JSONSerializer(out);
25 serializer.getPropertyFilters().add(filter);
FastJsonObjectInput.java (https://github.com/redcreen/rpcplus.git) Java · 135 lines
14 * limitations under the License.
15 */
16 package com.redcreen.rpcplus.handler.codec.serialize.fastjson;
18 import java.io.BufferedReader;
24 import java.util.Map;
26 import com.alibaba.fastjson.JSON;
27 import com.redcreen.rpcplus.handler.codec.serialize.ObjectInput;
31 *
32 */
33 public class FastJsonObjectInput implements ObjectInput {
35 private final BufferedReader reader;
NumberValueTest_error_13.java (https://github.com/alibaba/fastjson.git) Java · 409 lines
1 package com.alibaba.json.bvt.parser.number;
3 import com.alibaba.fastjson.*;
4 import com.alibaba.fastjson.serializer.SerializerFeature;
219 Exception error = null;
220 try {
221 JSONObject jsonObject = JSON.parseObject("{\"v17\":49e99999999}");
222 jsonObject.getObject("v17", TimeUnit.class);
241 public void test_20() throws Exception {
242 JSONObject jsonObject = JSON.parseObject("{\"v\":49e99999999}");
243 Exception error = null;
244 try {
274 public void test_23() throws Exception {
275 JSONObject jsonObject = JSON.parseObject("{\"v\":49e99999999}");
276 Exception error = null;
277 try {
FastjsonManualCodec.java (https://github.com/alibaba/fastjson.git) Java · 188 lines
7 import java.util.List;
9 import com.alibaba.fastjson.JSON;
10 import com.alibaba.fastjson.parser.DefaultJSONParser;
11 import com.alibaba.fastjson.parser.Feature;
12 import com.alibaba.fastjson.parser.ParserConfig;
13 import com.alibaba.fastjson.serializer.JSONSerializer;
14 import com.alibaba.fastjson.serializer.ObjectSerializer;
15 import com.alibaba.fastjson.serializer.SerializeConfig;
16 import com.alibaba.fastjson.serializer.SerializeWriter;
28 public FastjsonManualCodec(){
29 System.out.println("fastjson-" + JSON.VERSION);
31 serializeConfig.put(MediaContent.class, new MediaContentSerializer());
PlatformDepartmentVO.java (https://github.com/alibaba/fastjson.git) Java · 257 lines
1 package com.alibaba.json.bvtVO.alipay;
3 import com.alibaba.fastjson.annotation.JSONField;
5 import java.util.ArrayList;
11 @JSONField(ordinal=2)
12 private String label ;
13 @JSONField(ordinal=3)
14 private String value;
15 @JSONField(ordinal=4)
19 @JSONField(ordinal=6)
20 private String companyId;
21 @JSONField(ordinal=7)
22 private String departCode;
23 @JSONField(ordinal=8)
RatingDetailBO.java (https://github.com/alibaba/fastjson.git) Java · 463 lines
1 package com.alibaba.json.bvt.issue_1600.issue_1699.obj;
3 import com.alibaba.fastjson.annotation.JSONType;
4 import com.alibaba.json.bvt.issue_1600.issue_1699.def.InnerTypeMEnum;
5 import com.alibaba.json.bvt.issue_1600.issue_1699.def.RatingDetailIsJoinMEnum;
6 import com.alibaba.json.bvt.issue_1600.issue_1699.def.*;
FastJsonConfig.java (https://github.com/alibaba/fastjson.git) Java · 257 lines
2 package com.alibaba.fastjson.support.config;
4 import com.alibaba.fastjson.parser.Feature;
5 import com.alibaba.fastjson.parser.ParserConfig;
6 import com.alibaba.fastjson.parser.deserializer.ParseProcess;
7 import com.alibaba.fastjson.serializer.SerializeConfig;
8 import com.alibaba.fastjson.serializer.SerializeFilter;
9 import com.alibaba.fastjson.serializer.SerializerFeature;
10 import com.alibaba.fastjson.util.IOUtils;
16 /**
17 * Config for FastJson.
18 *
19 * @author VictorZeng
JSONScannerTest_new.java (https://github.com/alibaba/fastjson.git) Java · 126 lines
1 package com.alibaba.json.bvt.parser;
3 import org.junit.Assert;
6 import com.alibaba.fastjson.JSONException;
7 import com.alibaba.fastjson.parser.JSONScanner;
9 public class JSONScannerTest_new extends TestCase {
11 public void test_scan_new_0() throws Exception {
12 JSONScanner lexer = new JSONScanner("new");
13 lexer.scanNullOrNew();
14 }
122 public void test_scan_new_15() throws Exception {
123 JSONScanner lexer = new JSONScanner("new]");
124 lexer.scanNullOrNew();
125 }
PayRouteService.java (https://github.com/Martin404/PayMap.git) Java · 175 lines
1 package com.hugnew.sps.services.impls;
3 import com.alibaba.fastjson.JSON;
4 import com.hugnew.sps.dao.*;
5 import com.hugnew.sps.dao.domain.*;
140 public Boolean getPayRetMap4MQ(PayRequestParam payRequestParam) {
141 Map<String, Object> retMap = assembleRetMap(payRequestParam);
142 amqpTemplate.convertAndSend("payRequestCallback." + payRequestParam.getRequestBiz() + payRequestParam.getOrderCode(), JSON.toJSONString(retMap));
143 return true;
144 }
TestUTF8_3.java (https://github.com/flydream/fastjson.git) Java · 221 lines
PropertyFilter_long.java (https://github.com/alibaba/fastjson.git) Java · 149 lines
1 package com.alibaba.json.bvt.serializer.filters;
3 import java.util.HashMap;
7 import junit.framework.TestCase;
9 import com.alibaba.fastjson.serializer.JSONSerializer;
10 import com.alibaba.fastjson.serializer.PropertyFilter;
11 import com.alibaba.fastjson.serializer.SerializeWriter;
13 public class PropertyFilter_long extends TestCase {
23 SerializeWriter out = new SerializeWriter();
24 JSONSerializer serializer = new JSONSerializer(out);
25 serializer.getPropertyFilters().add(filter);
PropertyFilter_byte.java (https://github.com/alibaba/fastjson.git) Java · 149 lines
1 package com.alibaba.json.bvt.serializer.filters;
3 import java.util.HashMap;
7 import junit.framework.TestCase;
9 import com.alibaba.fastjson.serializer.JSONSerializer;
10 import com.alibaba.fastjson.serializer.PropertyFilter;
11 import com.alibaba.fastjson.serializer.SerializeWriter;
13 public class PropertyFilter_byte extends TestCase {
23 SerializeWriter out = new SerializeWriter();
24 JSONSerializer serializer = new JSONSerializer(out);
25 serializer.getPropertyFilters().add(filter);
DefaultObjectDeserializerTest2.java (https://github.com/flydream/fastjson.git) Java · 145 lines
11 import junit.framework.TestCase;
13 import com.alibaba.fastjson.JSON;
14 import com.alibaba.fastjson.JSONObject;
15 import com.alibaba.fastjson.TypeReference;
16 import com.alibaba.fastjson.parser.DefaultExtJSONParser;
17 import com.alibaba.fastjson.parser.ParserConfig;
105 public void test_7() throws Exception {
106 String input = "{'map':{}}";
107 DefaultExtJSONParser parser = new DefaultExtJSONParser(input, ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);
109 DefaultObjectDeserializer deser = new DefaultObjectDeserializer();
126 public void test_error() throws Exception {
127 String input = "{'map':{}}";
128 DefaultExtJSONParser parser = new DefaultExtJSONParser(input, ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);
130 DefaultObjectDeserializer deser = new DefaultObjectDeserializer();
Bug_for_lenolix_8.java (https://github.com/alibaba/fastjson.git) Java · 112 lines
1 package com.alibaba.json.bvt.bug;
3 import java.io.Serializable;
12 import junit.framework.TestCase;
14 import com.alibaba.fastjson.JSON;
15 import com.alibaba.fastjson.serializer.SerializerFeature;
20 JSON.defaultLocale = Locale.CHINA;
22 com.alibaba.fastjson.parser.ParserConfig.global.addAccept("com.alibaba.json.bvt.bug.Bug_for_lenolix_8.");
23 }
37 map.put(1, user);
39 String mapJson = JSON.toJSONString(map, SerializerFeature.WriteClassName, SerializerFeature.WriteMapNullValue);
41 System.out.println(mapJson);
FieldInfo.java (https://bitbucket.org/xiejuntao/xdesktop.git) Java · 227 lines
WallResult.java (https://github.com/alibaba/druid.git) Java · 117 lines
1 package com.alibaba.druid.admin.model.dto;
3 import com.alibaba.fastjson2.annotation.JSONField;
4 import lombok.Data;
5 import lombok.NoArgsConstructor;
40 @JSONField(name = "whiteListSize")
41 private int whiteListSize;
42 @JSONField(name = "syntaxErrorCount")
43 private int syntaxErrorCount;
44 @JSONField(name = "tables")
79 @Data
80 public static class WhiteListBean {
81 @JSONField(name = "sql")
82 private String sql;
83 @JSONField(name = "sample")
HSFJSONUtilsTest_0.java (https://github.com/alibaba/fastjson.git) Java · 232 lines
1 package com.alibaba.json.bvt.support.hsf;
3 import com.alibaba.fastjson.support.hsf.HSFJSONUtils;
4 import com.alibaba.fastjson.support.hsf.MethodLocator;
31 }
33 if (types.length == 1 && types[0].equals("com.alibaba.json.bvt.support.hsf.HSFJSONUtilsTest_0.User[]")) {
34 return method_f5;
35 }
70 String json = "{ \n" +
71 " \"argsTypes\" : [ \"java.lang.String\", \"com.alibaba.json.bvt.support.hsf.HSFJSONUtilsTest_0$Model\"],\n" +
72 " \"argsObjs\" : [ null, null ]\n" +
73 "}";
190 String json = "{ \n" +
191 " \"argsTypes\" : [ \"java.lang.String\", \"com.alibaba.json.bvt.support.hsf.HSFJSONUtilsTest_0$Model\"],\n" +
192 " \"argsObjs\" : [ \"abc\", {\"value\":\"xxx\"} ]\n" +
193 "}";
JSONPath_field_access_filter_in_decimal.java (https://github.com/alibaba/fastjson.git) Java · 139 lines
1 package com.alibaba.json.bvt.path;
3 import com.alibaba.fastjson.JSONPath;
4 import junit.framework.TestCase;
5 import org.junit.Assert;
13 public void test_list_in() throws Exception {
14 JSONPath path = new JSONPath("[id in (1001)]");
16 List<Entity> entities = new ArrayList<Entity>();
27 public void test_list_not_in() throws Exception {
28 JSONPath path = new JSONPath("[id not in (1001)]");
30 List<Entity> entities = new ArrayList<Entity>();
Issue1496.java (https://github.com/alibaba/fastjson.git) Java · 201 lines
1 package com.alibaba.json.bvt.issue_1400;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.annotation.JSONType;
5 import com.alibaba.fastjson.serializer.SerializeConfig;
6 import junit.framework.TestCase;
11 public class Issue1496 extends TestCase {
12 public void test_for_issue() throws Exception {
13 String json = JSON.toJSONString(SetupStatus.FINAL_TRAIL);
14 assertEquals("{\"canRefuse\":true,\"code\":3,\"declaringClass\":\"com.alibaba.json.bvt.issue_1400.Issue1496$SetupStatus\",\"first\":false,\"last\":false,\"name\":\"FINAL_TRAIL\",\"nameCn\":\"公益委员会/理事会/理事长审核\"}", json);
41 }
43 @JSONType(serializeEnumAsJavaBean = true)
44 public enum SetupStatus implements ISetupStatusInfo, ISetupStatusProcess {
45 EDIT(0, "EDIT", "编辑中") {
JSONScannerTest_null.java (https://github.com/flydream/fastjson.git) Java · 126 lines
1 package com.alibaba.json.bvt.parser;
3 import junit.framework.Assert;
6 import com.alibaba.fastjson.JSONException;
7 import com.alibaba.fastjson.parser.JSONScanner;
9 public class JSONScannerTest_null extends TestCase {
11 public void test_scan_null_0() throws Exception {
12 JSONScanner lexer = new JSONScanner("null");
13 lexer.scanNullOrNew();
14 }
122 public void test_scan_false_15() throws Exception {
123 JSONScanner lexer = new JSONScanner("null]");
124 lexer.scanNullOrNew();
125 }
EnumDeserializer.java (https://github.com/flydream/fastjson.git) Java · 82 lines
1 package com.alibaba.fastjson.parser.deserializer;
3 import java.lang.reflect.Method;
6 import java.util.Map;
8 import com.alibaba.fastjson.JSONException;
9 import com.alibaba.fastjson.parser.DefaultJSONParser;
10 import com.alibaba.fastjson.parser.JSONLexer;
11 import com.alibaba.fastjson.parser.JSONToken;
46 T e = (T) ordinalMap.get(value);
47 if (e == null) {
48 throw new JSONException("parse enum " + enumClass.getName() + " error, value : " + value);
49 }
50 return e;
LongFieldTest.java (https://github.com/flydream/fastjson.git) Java · 83 lines
4 import junit.framework.TestCase;
6 import com.alibaba.fastjson.JSON;
7 import com.alibaba.fastjson.parser.ParserConfig;
8 import com.alibaba.fastjson.serializer.SerializeConfig;
9 import com.alibaba.fastjson.serializer.SerializerFeature;
11 public class LongFieldTest extends TestCase {
15 v.setValue(1001L);
17 String text = JSON.toJSONString(v);
18 System.out.println(text);
43 mapping.setAsmEnable(true);
45 String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
46 Assert.assertEquals("{\"value\":null}", text);
FieldDeserializer.java (https://github.com/alibaba/fastjson.git) Java · 261 lines
1 package com.alibaba.fastjson.parser.deserializer;
3 import com.alibaba.fastjson.JSONException;
4 import com.alibaba.fastjson.parser.DefaultJSONParser;
5 import com.alibaba.fastjson.parser.ParserConfig;
6 import com.alibaba.fastjson.serializer.BeanContext;
7 import com.alibaba.fastjson.util.FieldInfo;
8 import com.alibaba.fastjson.util.TypeUtils;
33 }
35 public abstract void parseField(DefaultJSONParser parser, Object object, Type objectType,
36 Map<String, Object> fieldValues);
JavaBeanSerializerTest.java (https://github.com/flydream/fastjson.git) Java · 215 lines
1 package com.alibaba.json.bvt.serializer;
3 import java.util.ArrayList;
8 import junit.framework.TestCase;
10 import com.alibaba.fastjson.JSONException;
11 import com.alibaba.fastjson.serializer.FieldSerializer;
12 import com.alibaba.fastjson.serializer.JSONSerializer;
13 import com.alibaba.fastjson.serializer.JavaBeanSerializer;
14 import com.alibaba.fastjson.serializer.SerializeWriter;
16 public class JavaBeanSerializerTest extends TestCase {
47 JavaBeanSerializer serializer = new JavaBeanSerializer(F.class);
48 serializer.write(new JSONSerializer(out), new F(new E(123)), null, null);
50 Assert.assertEquals("{\"e\":{\"id\":123}}", out.toString());
AbstractJSONParser.java (https://github.com/flydream/fastjson.git) Java · 240 lines
3 import static com.alibaba.fastjson.parser.JSONToken.EOF;
4 import static com.alibaba.fastjson.parser.JSONToken.FALSE;
5 import static com.alibaba.fastjson.parser.JSONToken.LBRACE;
6 import static com.alibaba.fastjson.parser.JSONToken.LBRACKET;
7 import static com.alibaba.fastjson.parser.JSONToken.LITERAL_FLOAT;
8 import static com.alibaba.fastjson.parser.JSONToken.LITERAL_INT;
9 import static com.alibaba.fastjson.parser.JSONToken.LITERAL_STRING;
10 import static com.alibaba.fastjson.parser.JSONToken.NEW;
11 import static com.alibaba.fastjson.parser.JSONToken.NULL;
12 import static com.alibaba.fastjson.parser.JSONToken.RBRACKET;
13 import static com.alibaba.fastjson.parser.JSONToken.SET;
14 import static com.alibaba.fastjson.parser.JSONToken.TREE_SET;
15 import static com.alibaba.fastjson.parser.JSONToken.TRUE;
FastJsonObjectOutput.java (https://github.com/apache/incubator-dubbo.git) Java · 113 lines
15 * limitations under the License.
16 */
17 package org.apache.dubbo.common.serialize.fastjson;
19 import org.apache.dubbo.common.serialize.ObjectOutput;
21 import com.alibaba.fastjson.serializer.JSONSerializer;
22 import com.alibaba.fastjson.serializer.SerializeWriter;
23 import com.alibaba.fastjson.serializer.SerializerFeature;
25 import java.io.IOException;
31 /**
32 * FastJson object output implementation
33 */
34 public class FastJsonObjectOutput implements ObjectOutput {
DataSourceResult.java (https://github.com/alibaba/druid.git) Java · 163 lines
1 package com.alibaba.druid.admin.model.dto;
3 import com.alibaba.fastjson2.annotation.JSONField;
4 import lombok.Data;
5 import lombok.NoArgsConstructor;
84 @JSONField(name = "LogicConnectCount")
85 private int LogicConnectCount;
86 @JSONField(name = "LogicCloseCount")
87 private int LogicCloseCount;
88 @JSONField(name = "LogicConnectErrorCount")
89 private int LogicConnectErrorCount;
90 @JSONField(name = "PhysicalConnectCount")
91 private int PhysicalConnectCount;
92 @JSONField(name = "PhysicalCloseCount")
126 @JSONField(name = "KeepAlive")
127 private boolean KeepAlive;
128 @JSONField(name = "FailFast")
129 private boolean FailFast;
SymbolTableDupTest.java (https://github.com/alibaba/fastjson.git) Java · 108 lines
TypeUtilsTest_interface.java (https://github.com/alibaba/fastjson.git) Java · 136 lines
1 package com.alibaba.json.bvt.parser;
3 import java.util.ArrayList;
8 import org.junit.Assert;
10 import com.alibaba.fastjson.JSON;
11 import com.alibaba.fastjson.TypeReference;
12 import com.alibaba.fastjson.annotation.JSONField;
14 public class TypeUtilsTest_interface extends TestCase {
19 vo.setName("abc");
21 Assert.assertEquals("{\"ID\":123,\"name\":\"abc\"}", JSON.toJSONString(vo));
22 }
ParserConfigBug569.java (https://github.com/alibaba/fastjson.git) Java · 194 lines
1 package com.alibaba.fastjson.deserializer.issues569.parser;
3 import com.alibaba.fastjson.JSONException;
4 import com.alibaba.fastjson.annotation.JSONField;
5 import com.alibaba.fastjson.annotation.JSONType;
6 import com.alibaba.fastjson.parser.ParserConfig;
7 import com.alibaba.fastjson.parser.deserializer.*;
8 import com.alibaba.fastjson.serializer.AwtCodec;
9 import com.alibaba.fastjson.serializer.CollectionCodec;
10 import com.alibaba.fastjson.serializer.MiscCodec;
11 import com.alibaba.fastjson.serializer.ObjectArrayCodec;
12 import com.alibaba.fastjson.util.FieldInfo;
13 import com.alibaba.fastjson.util.JavaBeanInfo;
JSONScannerTest__nextToken.java (https://github.com/alibaba/fastjson.git) Java · 106 lines
6 import com.alibaba.fastjson.parser.JSONScanner;
7 import com.alibaba.fastjson.parser.JSONToken;
9 public class JSONScannerTest__nextToken extends TestCase {
10 public void test_next() throws Exception {
11 String text = "\"aaa\"";
12 JSONScanner lexer = new JSONScanner(text);
13 lexer.nextToken(JSONToken.LITERAL_INT);
80 public void test_next_10() throws Exception {
81 String text = "\n\r\t\f\b :";
82 JSONScanner lexer = new JSONScanner(text);
83 lexer.nextTokenWithColon(JSONToken.LBRACE);
100 public void test_next_13() throws Exception {
101 String text = "\n\r\t\f\b :\n\r\t\f\b ";
102 JSONScanner lexer = new JSONScanner(text);
103 lexer.nextTokenWithColon(JSONToken.LBRACKET);
ImageGenDecoder.java (https://github.com/alibaba/fastjson.git) Java · 179 lines
3 import java.lang.reflect.Type;
5 import com.alibaba.fastjson.parser.DefaultJSONParser;
6 import com.alibaba.fastjson.parser.Feature;
7 import com.alibaba.fastjson.parser.JSONLexerBase;
8 import com.alibaba.fastjson.parser.ParseContext;
9 import com.alibaba.fastjson.parser.ParserConfig;
10 import com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer;
11 import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
13 public class ImageGenDecoder extends JavaBeanDeserializer implements ObjectDeserializer {
33 public Object deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
34 JSONLexerBase lexer = (JSONLexerBase) parser.getLexer();
36 if (!lexer.isEnabled(Feature.SortFeidFastMatch)) {
JSONPath_extract_2_book.java (https://github.com/alibaba/fastjson.git) Java · 128 lines
1 package com.alibaba.json.bvt.path.extract;
3 import com.alibaba.fastjson.JSONPath;
4 import com.alibaba.fastjson.util.IOUtils;
12 public void test_0() throws Exception {
13 assertEquals("[\"Nigel Rees\",\"Evelyn Waugh\",\"Herman Melville\",\"J. R. R. Tolkien\"]"
14 , JSONPath.extract(json, "$.store.book.author")
15 .toString());
16 }
69 assertEquals("Evelyn Waugh"
70 , JSONPath.extract(json, "$['store']['book'][1]['author']")
71 .toString());
116 public void test_17() throws Exception {
117 assertEquals(4, JSONPath.extract(json, "$..book.length()"));
118 }
HttpRequest.java (https://gitlab.com/GavinGJ/MATIRX) Java · 137 lines
HttpTestEasyAccount001.java (https://github.com/tronprotocol/sun-network.git) Java · 291 lines
2 import org.tron.core.Wallet;
4 import com.alibaba.fastjson.JSONObject;
5 import lombok.extern.slf4j.Slf4j;
6 import org.apache.http.HttpResponse;
237 HttpMethed.printJsonContent(responseContent);
238 afterEasyAsset = responseContent.getJSONArray("assetV2").getJSONObject(0)
239 .getLongValue("value");
240 logger.info("afterEasyAsset:" + afterEasyAsset);
244 HttpMethed.printJsonContent(responseContent);
245 beforeGenerateAsset = responseContent.getJSONArray("assetV2").getJSONObject(0)
246 .getLongValue("value");
247 logger.info("beforeGenerateAsset:" + beforeGenerateAsset);
275 HttpMethed.printJsonContent(responseContent);
276 afterGenerateAsset = responseContent.getJSONArray("assetV2").getJSONObject(0)
277 .getLongValue("value");
278 logger.info("afterGenerateAsset:" + afterGenerateAsset);
WriteAsArray_string.java (https://github.com/alibaba/fastjson.git) Java · 99 lines
3 import org.junit.Assert;
5 import com.alibaba.fastjson.JSON;
6 import com.alibaba.fastjson.JSONException;
7 import com.alibaba.fastjson.parser.Feature;
8 import com.alibaba.fastjson.serializer.SerializerFeature;
15 Model model = new Model();
17 String text = JSON.toJSONString(model, SerializerFeature.BeanToArray);
18 Assert.assertEquals("[null]", text);
25 Model model = new Model();
26 model.name = "abc";
27 String text = JSON.toJSONString(model, SerializerFeature.BeanToArray);
28 Assert.assertEquals("[\"abc\"]", text);
DefaultFieldDeserializerBug569.java (https://github.com/alibaba/fastjson.git) Java · 67 lines
1 package com.alibaba.fastjson.deserializer.issues569.parser;
3 import com.alibaba.fastjson.parser.DefaultJSONParser;
4 import com.alibaba.fastjson.parser.ParseContext;
5 import com.alibaba.fastjson.parser.ParserConfig;
6 import com.alibaba.fastjson.parser.deserializer.ContextObjectDeserializer;
7 import com.alibaba.fastjson.parser.deserializer.DefaultFieldDeserializer;
8 import com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer;
9 import com.alibaba.fastjson.util.FieldInfo;
11 import java.lang.reflect.ParameterizedType;
24 @Override
25 public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
26 if (fieldValueDeserilizer == null) {
27 getFieldValueDeserilizer(parser.getConfig());
PrimitiveArraySerializer.java (https://github.com/alibaba/fastjson.git) Java · 136 lines
14 * limitations under the License.
15 */
16 package com.alibaba.fastjson.serializer;
18 import java.io.IOException;
26 public static PrimitiveArraySerializer instance = new PrimitiveArraySerializer();
28 public final void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
29 SerializeWriter out = serializer.out;
Issue3655.java (https://github.com/alibaba/fastjson.git) Java · 164 lines
1 package com.alibaba.json.bvt.issue_3600;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.serializer.SerializerFeature;
11 public class Issue3655 {
12 private final static String jsonStr =
13 "{\"data\":\"\",\"data2\":\"\",\"data3\":\"\",\"data4\":\"\",\"data5\":\"\",\"data6\":\"\",\"data7\":\"\",\"data8\":\"\",\"data9\":\"\"}";
16 public void test_inherit_from_abstract_class_1() {
17 issue3655_b b = new issue3655_b(null, null, null, null, null, null, null, null, null);
18 String result = JSON.toJSONString(b, SerializerFeature.WriteNullStringAsEmpty);
19 System.out.println(result);
20 Assert.assertEquals(jsonStr, result);
24 public void test_inherit_from_abstract_class_2() {
25 issue3655_c c = new issue3655_c(null, null, null, null, null, null, null, null, null);
26 String result = JSON.toJSONString(c, SerializerFeature.WriteNullStringAsEmpty);
27 System.out.println(result);
28 Assert.assertEquals(jsonStr, result);
Topic.java (https://github.com/didi/DDMQ.git) Java · 441 lines
6 import java.util.Map;
8 import com.alibaba.fastjson.TypeReference;
9 import com.didi.carrera.console.common.util.FastJsonUtils;
197 public String getAlarmGroup() {
198 return this.alarmGroup == null ? null : FastJsonUtils.toJsonString(alarmGroup);
199 }
253 public String getProduceModeMapper() {
254 return this.produceModeMapper == null ? null : FastJsonUtils.toJsonString(produceModeMapper);
255 }
287 public String getConfig() {
288 return this.config == null ? null : FastJsonUtils.toJsonString(config);
289 }
DBManager.java (https://github.com/githuanl/socket.io-android-client.git) Java · 403 lines
6 import android.text.TextUtils;
8 import com.alibaba.fastjson.JSON;
9 import com.centersoft.base.ChatApplication;
10 import com.centersoft.db.dao.ConversationDao;
61 values.put(VFMessageDao.COLUMN_NAME_CHAT_TYPE, message.getChat_type().toString());
62 values.put(VFMessageDao.COLUMN_NAME_EXT, message.getExt());
63 values.put(VFMessageDao.COLUMN_NAME_BODIES, JSON.toJSONString(message.getBodies()));
65 db.insert(VFMessageDao.TABLE_NAME, null, values);
101 values.put(VFMessageDao.COLUMN_NAME_CHAT_TYPE, message.getChat_type().toString());
102 values.put(VFMessageDao.COLUMN_NAME_EXT, message.getExt());
103 values.put(VFMessageDao.COLUMN_NAME_BODIES, JSON.toJSONString(message.getBodies()));
105 db.insert(VFMessageDao.TABLE_NAME, null, values);
DefaultObjectDeserializer.java (https://github.com/flydream/fastjson.git) Java · 356 lines
1 package com.alibaba.fastjson.parser.deserializer;
3 import java.lang.reflect.Method;
16 import java.util.concurrent.ConcurrentMap;
18 import com.alibaba.fastjson.JSONException;
19 import com.alibaba.fastjson.parser.DefaultJSONParser;
20 import com.alibaba.fastjson.parser.Feature;
21 import com.alibaba.fastjson.parser.JSONScanner;
22 import com.alibaba.fastjson.parser.JSONToken;
23 import com.alibaba.fastjson.util.ASMClassLoader;
24 import com.alibaba.fastjson.util.TypeUtils;
31 public void parseMap(DefaultJSONParser parser, Map<Object, Object> map, Type keyType, Type valueType, Object fieldName) {
32 JSONScanner lexer = (JSONScanner) parser.getLexer();
34 if (lexer.token() != JSONToken.LBRACE) {
UrlParamsBuilder.java (https://github.com/HuobiRDCenter/huobi_Java.git) Java · 208 lines
11 import java.util.TreeMap;
13 import com.alibaba.fastjson.JSON;
14 import okhttp3.MediaType;
15 import okhttp3.RequestBody;
174 return RequestBody.create(JSON_TYPE, "");
175 } else {
176 return RequestBody.create(JSON_TYPE, JSON.toJSONString(postBodyMap.map));
177 }
178 } else {
179 return RequestBody.create(JSON_TYPE, JSON.toJSONString(postBodyMap.stringListMap));
DbNodeServiceImplTest.java (https://github.com/ppdaicorp/pmq.git) Java · 339 lines
20 import org.springframework.test.util.ReflectionTestUtils;
22 import com.alibaba.druid.pool.DruidDataSource;
23 import com.ppdai.infrastructure.mq.biz.AbstractTest;
24 import com.ppdai.infrastructure.mq.biz.dal.meta.DbNodeRepository;
195 dbNodeServiceImpl.startPortal();
196 dbNodeServiceImpl.info();
197 dbNodeServiceImpl.getCacheJson();
198 dbNodeServiceImpl.getDataSource();
199 dbNodeServiceImpl.getCacheByIp();