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());
Base64.java (https://github.com/alibaba/fastjson.git) Java · 210 lines
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 }
TypeUtilsTest.java (https://github.com/flydream/fastjson.git) Java · 418 lines
17 import com.alibaba.fastjson.JSON;
18 import com.alibaba.fastjson.JSONException;
19 import com.alibaba.fastjson.JSONObject;
113 public void test_cast_to_Boolean() throws Exception {
114 JSONObject json = new JSONObject();
115 json.put("id", 1);
213 long millis = System.currentTimeMillis();
215 JSONObject json = new JSONObject();
216 json.put("date", millis);
221 long millis = System.currentTimeMillis();
223 JSONObject json = new JSONObject();
224 json.put("date", Long.toString(millis));
SerializeWriterTest.java (https://github.com/alibaba/fastjson.git) Java · 229 lines
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;
18 import com.alibaba.fastjson.parser.JSONLexer;
19 import com.alibaba.fastjson.parser.JSONReaderScanner;
20 import com.alibaba.fastjson.parser.JSONToken;
TypeUtilstTest.java (https://github.com/alibaba/fastjson.git) Java · 233 lines
14 * limitations under the License.
15 */
16 package com.alibaba.json.bvt;
18 import java.math.BigDecimal;
24 import junit.framework.TestCase;
26 import com.alibaba.fastjson.JSON;
28 public class TypeUtilstTest extends TestCase {
58 }
60 String jsonString = JSON.toJSONString(personList);
63 JSON.parseArray(jsonString, Person.class);
64 // CGLibExtJSONParser parser = new CGLibExtJSONParser(text);
JSONObjectTest_readObject.java (https://github.com/alibaba/fastjson.git) Java · 156 lines
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 }
136 ParserConfig.global.setSafeMode(true);
137 try {
138 JSONObject jsonObject = new JSONObject();
139 jsonObject.put("m", new java.util.HashMap());
SqlCodeStat.java (https://github.com/alibaba/druid.git) Java · 359 lines
12 import com.alibaba.druid.sql.dialect.odps.visitor.OdpsASTVisitorAdapter;
13 import com.alibaba.druid.sql.parser.SQLParserFeature;
14 import com.alibaba.fastjson2.JSON;
15 import com.alibaba.fastjson2.JSONWriter;
16 import com.alibaba.fastjson2.annotation.JSONField;
17 import com.aliyun.odps.udf.UDF;
347 public String toString() {
348 return JSON.toJSONString(
349 stat,
350 JSONWriter.Feature.PrettyFormat,
355 public java.util.Map toMap() {
356 return (java.util.Map) JSON.toJSON(stat);
357 }
358 }
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;
354 public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
355 JSONObject jsonObject = (JSONObject) parser.parse();
356 String areaType;
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) {
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));
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);
LargeJavaBean.java (https://github.com/alibaba/fastjson.git) Java · 615 lines
1 package com.alibaba.fastjson.deserializer.issue2779;
3 import java.util.List;
516 }
518 // provide by zhaiyao, for fastjson test
519 private List<Alphabet> list100;
520 private List<Alphabet> list101;
585 public static class Alphabet {
586 // provide by zhaiyao, for fastjson test
587 private List<Double> a;
588 private List<Double> b;
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;
BookEvalTest.java (https://github.com/alibaba/fastjson.git) Java · 105 lines
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject;
5 import com.alibaba.fastjson.JSONPath;
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 }
65 public void test_9() throws Exception {
66 assertEquals("{\"category\":\"fiction\",\"author\":\"J. R. R. Tolkien\",\"title\":\"The Lord of the Rings\",\"isbn\":\"0-395-19395-8\",\"price\":22.99}"
67 , JSON.toJSONString(JSONPath.eval(root, "$..book[-1]")));
68 }
100 public void test_16() throws Exception {
101 assertEquals("[{\"category\":\"fiction\",\"author\":\"Herman Melville\",\"title\":\"Moby Dick\",\"isbn\":\"0-553-21311-3\",\"price\":8.99}]"
102 , JSON.toJSONString(JSONPath.eval(root, "$.store.book[?(@.price < 10 && @.category == 'fiction')]")));
103 }
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;
20 public class DefaultFieldDeserializer extends FieldDeserializer {
JSONPath_field_access_filter_in_int.java (https://github.com/alibaba/fastjson.git) Java · 151 lines
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
ListStringFieldTest_stream.java (https://github.com/alibaba/fastjson.git) Java · 208 lines
9 import com.alibaba.fastjson.JSONException;
10 import com.alibaba.fastjson.JSONReader;
11 import com.alibaba.fastjson.TypeReference;
18 String text = "{\"values\":[\"a\",null,\"b\",\"ab\\\\c\\\"\"]}";
20 JSONReader reader = new JSONReader(new StringReader(text));
21 Model model = reader.readObject(Model.class);
22 Assert.assertEquals(4, model.values.size());
59 public void test_error() throws Exception {
60 String text = "{\"values\":[1";
61 JSONReader reader = new JSONReader(new StringReader(text));
63 Exception error = null;
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;
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);
134 mapping.setAsmEnable(true);
136 String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
137 Assert.assertEquals("{\"value\":" + Long.MIN_VALUE + "}", text);
Item.java (https://github.com/alibaba/fastjson.git) Java · 177 lines
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());
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);
ClobSerializerTest.java (https://github.com/alibaba/fastjson.git) Java · 144 lines
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 }
30 Exception error = null;
31 try {
32 JSON.toJSONString(new MockClob(new SQLException()));
33 } catch (Exception ex) {
34 error = ex;
TestForDubbo.java (https://github.com/alibaba/fastjson.git) Java · 83 lines
6 import junit.framework.TestCase;
8 import com.alibaba.fastjson.JSON;
9 import com.alibaba.fastjson.serializer.SerializerFeature;
57 Tigers tigers = helloService.eatTiger(tiger);
59 String text = JSON.toJSONString(tigers, SerializerFeature.WriteClassName);
60 System.out.println(text);
62 Tigers tigers2 = JSON.parseObject(text, Tigers.class);
64 Assert.assertEquals(text, JSON.toJSONString(tigers2, SerializerFeature.WriteClassName));
65 }
67 public void testPerson() {
68 Person p = helloService.showPerson(person);
69 String text = JSON.toJSONString(p, SerializerFeature.WriteClassName);
70 System.out.println(text);
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 }
TypeUtilsTest_castToJavaBean.java (https://github.com/alibaba/fastjson.git) Java · 254 lines
8 import java.util.concurrent.ConcurrentMap;
10 import com.alibaba.fastjson.parser.ParserConfig;
11 import org.junit.Assert;
13 import com.alibaba.fastjson.JSON;
14 import com.alibaba.fastjson.serializer.JSONSerializer;
15 import com.alibaba.fastjson.serializer.JavaBeanSerializer;
16 import com.alibaba.fastjson.serializer.SerializeConfig;
17 import com.alibaba.fastjson.serializer.SerializeWriter;
18 import com.alibaba.fastjson.util.TypeUtils;
UTF8Decoder.java (https://bitbucket.org/xiejuntao/xdesktop.git) Java · 215 lines
AppDailyData.java (https://github.com/sohutv/cachecloud.git) Java · 392 lines
LongFieldTest_2.java (https://github.com/alibaba/fastjson.git) Java · 117 lines
1 package com.alibaba.json.bvt;
3 import com.alibaba.fastjson.JSONReader;
4 import org.junit.Assert;
6 import com.alibaba.fastjson.JSON;
7 import com.alibaba.fastjson.parser.Feature;
51 v.setValue(Long.MAX_VALUE);
53 String text = JSON.toJSONString(v);
55 V0 v1 = new JSONReader(new StringReader(text)).readObject(V0.class);
73 v.setValue(Long.MIN_VALUE);
75 String text = JSON.toJSONString(v, SerializerFeature.BeanToArray);
77 V0 v1 = new JSONReader(new StringReader(text), Feature.SupportArrayToBean).readObject(V0.class);
Bug_for_rd.java (https://github.com/alibaba/fastjson.git) Java · 94 lines
1 package com.alibaba.json.bvt.bug;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject;
11 String json = "{ \"sitePayId\": \"2019071889031100000152604119889\", \"extendInfo\": \"{\\\"saveAsset\\\":\\\"false\\\",\\\"acquirementId\\\":\\\"20190718194010800100177150204979354\\\",\\\"orderTerminalType\\\":\\\"WEB\\\",\\\"acqSiteUserId\\\":\\\"2177220032166157\\\",\\\"siteReqBizId\\\":\\\"111023437\\\",\\\"msisdn\\\":\\\"01966114400\\\",\\\"originalMerchantOrderId\\\":\\\"602109378031994\\\"}\", \"netPayId\": \"2019071819039101720000454701\", \"resultInfo\": { \"resultCode\": \"SUCCESS\", \"resultCodeId\": \"00000000\", \"resultMsg\": \"Success\", \"resultStatus\": \"S\" } }";
12 PayResponse object = JSON.parseObject(json, PayResponse.class);
13 String extendInfo = object.getExtendInfo();
31 String json = "{\"sitePayId\": \"MINUTES\\\"A\"}";
32 V1 v = JSON.parseObject(json, V1.class);
33 assertEquals("MINUTES\"A", v.sitePayId);
34 }
49 String json = "{ \"sitePayId\": \"S\"}";
50 V1 v = JSON.parseObject(json, V1.class);
51 assertEquals("S", v.sitePayId);
52 }
DataTransaction.java (https://github.com/alibaba/fastjson.git) Java · 321 lines
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 }
316 System.out.println(dt.toJSON());
318 DataTransaction dt2 = DataTransaction.fromJSON(dt.toJSON());
319 System.out.println(dt2.toJSON());
LocalDateTimeTest5.java (https://github.com/alibaba/fastjson.git) Java · 183 lines
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());
102 public void test_for_kr() throws Exception {
103 VO vo = JSON.parseObject("{\"date\":\"2016년5월6일 09:03:16\"}", VO.class);
105 assertEquals(2016, vo.date.getYear());
JSONScannerTest_ISO8601.java (https://github.com/flydream/fastjson.git) Java · 121 lines
1 package com.alibaba.json.bvt.parser;
3 import junit.framework.Assert;
6 import com.alibaba.fastjson.parser.Feature;
7 import com.alibaba.fastjson.parser.JSONScanner;
8 import com.alibaba.fastjson.parser.JSONToken;
102 public void test_2() throws Exception {
103 JSONScanner lexer = new JSONScanner("2000-02-10T00:00:00.000");
104 lexer.config(Feature.AllowISO8601DateFormat, true);
105 Assert.assertEquals(true, lexer.scanISO8601DateIfMatch());
111 public void test_3() throws Exception {
112 JSONScanner lexer = new JSONScanner("2000-2");
113 lexer.config(Feature.AllowISO8601DateFormat, true);
114 lexer.nextToken();
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
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 }
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;
15 @Override
16 public void setUp() throws Exception {
17 String resource = "json/Issue408.json";
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);
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;
69 assertEquals("Evelyn Waugh"
70 , JSONPath.extract(json, "$['store']['book'][1]['author']")
71 .toString());
98 public void test_13() throws Exception {
99 assertEquals("J. R. R. Tolkien", JSONPath.extract(json, "$.store.book[3].author"));
100 }
121 private static String json;
122 static {
123 InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/book.json");
124 InputStreamReader reader = new InputStreamReader(is);
125 json = IOUtils.readAll(reader);
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 }
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;
DeserializeBeanInfo.java (https://bitbucket.org/xiejuntao/xdesktop.git) Java · 357 lines
11 import java.util.List;
13 import com.alibaba.fastjson.JSONException;
14 import com.alibaba.fastjson.annotation.JSONCreator;
15 import com.alibaba.fastjson.annotation.JSONField;
17 public class DeserializeBeanInfo {
184 }
186 JSONField annotation = method.getAnnotation(JSONField.class);
188 if (annotation != null) {
345 if (annotation != null) {
346 if (factoryMethod != null) {
347 throw new JSONException("multi-json creator");
348 }
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);
62 }
64 if (lexer.token() != JSONToken.LBRACKET) {
65 throw new JSONException("exepct '[', but " + lexer.token());
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
6 import com.alibaba.fastjson.JSON;
7 import com.alibaba.fastjson.JSONException;
9 public class StackTraceElementDeserializerTest extends TestCase {
12 Assert.assertNull(JSON.parseObject("null", StackTraceElement.class));
13 Assert.assertNull(JSON.parseArray("null", StackTraceElement.class));
14 Assert.assertNull(JSON.parseArray("[null]", StackTraceElement.class).get(0));
45 JSON.parseObject("{\"className\":null,\"methodName\":null,\"fileName\":null,\"lineNumber\":null,\"@type\":\"xxx\"}", StackTraceElement.class);
46 } catch (JSONException ex) {
47 error = ex;
48 }
83 Exception error = null;
84 try {
85 JSON.parseObject("{\"lineNumber\":33}", StackTraceElement.class);
86 } catch (JSONException ex) {
FieldInfo.java (https://bitbucket.org/xiejuntao/xdesktop.git) Java · 227 lines
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
1 package com.alibaba.fastjson.support.retrofit;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.parser.Feature;
7 import com.alibaba.fastjson.serializer.SerializerFeature;
8 import com.alibaba.fastjson.support.config.FastJsonConfig;
9 import okhttp3.MediaType;
10 import okhttp3.RequestBody;
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()
FastJsonHttpMessageConverterTest.java (https://github.com/alibaba/fastjson.git) Java · 201 lines
21 import com.alibaba.fastjson.serializer.SerializeFilter;
22 import com.alibaba.fastjson.serializer.SerializerFeature;
23 import com.alibaba.fastjson.serializer.ValueFilter;
24 import com.alibaba.fastjson.support.config.FastJsonConfig;
25 import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
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);
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);
Bug_for_km.java (https://github.com/alibaba/fastjson.git) Java · 129 lines
ListTypeFieldDeserializer.java (https://github.com/virjar/sekiro.git) Java · 255 lines
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;
47 }
49 JSONArray jsonArray = null;
50 List list;
51 if (array) {
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");
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);
103 public void test_4() throws Exception {
104 JSONSerializer serializer = new JSONSerializer(new SerializeWriter());
106 serializer.config(SerializerFeature.QuoteFieldNames, false);
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.*;
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) {
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;
36 Model model = new Model();
37 model.personId = 1001;
38 String text = JSON.toJSONString(model, config);
39 Assert.assertEquals("{\"person-id\":1001}", text);
54 Model model = new Model();
55 model.personId = 1001;
56 String text = JSON.toJSONString(model, config);
57 Assert.assertEquals("{\"PersonId\":1001}", text);
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) {
PropertyFilter_double.java (https://github.com/alibaba/fastjson.git) Java · 149 lines
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);
46 SerializeWriter out = new SerializeWriter();
47 JSONSerializer serializer = new JSONSerializer(out);
48 serializer.getPropertyFilters().add(filter);
PropertyFilter_short.java (https://github.com/alibaba/fastjson.git) Java · 149 lines
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);
46 SerializeWriter out = new SerializeWriter();
47 JSONSerializer serializer = new JSONSerializer(out);
48 serializer.getPropertyFilters().add(filter);
PropertyFilter_float.java (https://github.com/alibaba/fastjson.git) Java · 149 lines
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);
46 SerializeWriter out = new SerializeWriter();
47 JSONSerializer serializer = new JSONSerializer(out);
48 serializer.getPropertyFilters().add(filter);
SimplePropertyPreFilterTest.java (https://github.com/alibaba/fastjson.git) Java · 161 lines
7 import junit.framework.TestCase;
9 import com.alibaba.fastjson.JSON;
10 import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
35 public void test_name() throws Exception {
36 SimplePropertyPreFilter filter = new SimplePropertyPreFilter(VO.class, "name");
37 Assert.assertEquals("{\"name\":\"sandzhangtoo\"}", JSON.toJSONString(vo, filter));
38 }
65 public void test_id_0() throws Exception {
66 SimplePropertyPreFilter filter = new SimplePropertyPreFilter("id");
67 Assert.assertEquals("{\"id\":123}", JSON.toJSONString(vo, filter));
68 }
76 public void test_map_id() throws Exception {
77 SimplePropertyPreFilter filter = new SimplePropertyPreFilter("id");
78 Assert.assertEquals("{\"id\":123}", JSON.toJSONString(map, filter));
79 }
JSONPath_field_access_filter_compare_string_simple.java (https://github.com/alibaba/fastjson.git) Java · 157 lines
8 import org.junit.Assert;
10 import com.alibaba.fastjson.JSONPath;
12 public class JSONPath_field_access_filter_compare_string_simple extends TestCase {
14 public void test_list_eq() throws Exception {
15 JSONPath path = new JSONPath("[name = 'ljw2083']");
17 List<Entity> entities = new ArrayList<Entity>();
28 public void test_list_eq_x() throws Exception {
29 JSONPath path = new JSONPath("[name = 'ljw2083']");
31 List<Entity> entities = new ArrayList<Entity>();
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;
236 public void test_error_2() throws Exception {
237 String text = "{\"model\":[[][";
238 JSONReader reader = new JSONReader(new StringReader(text));
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
12 import com.alibaba.fastjson.JSON;
13 import com.alibaba.fastjson.JSONObject;
14 import com.alibaba.fastjson.serializer.SerializerFeature;
24 vo.setCalendar(Calendar.getInstance());
26 String text = JSON.toJSONString(vo);
28 VO vo1 = JSON.parseObject(text, VO.class);
32 public void test_format() throws Exception {
33 VO vo = new VO();
34 vo.setCalendar(Calendar.getInstance(JSON.defaultTimeZone, JSON.defaultLocale));
36 String text = JSON.toJSONString(vo, SerializerFeature.WriteDateUseDateFormat);
49 vo.setCalendar(Calendar.getInstance());
51 String text = JSON.toJSONString(vo, SerializerFeature.UseISO8601DateFormat);
53 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);
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){
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));
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;
19 @JSONField(ordinal=6)
20 private String companyId;
21 @JSONField(ordinal=7)
22 private String departCode;
23 @JSONField(ordinal=8)
24 private String memo;
25 @JSONField(ordinal=9)
26 private String departOrgCode;
27 @JSONField(ordinal=10)
DefaultObjectDeserializerTest2.java (https://github.com/flydream/fastjson.git) Java · 145 lines
13 import com.alibaba.fastjson.JSON;
14 import com.alibaba.fastjson.JSONObject;
15 import com.alibaba.fastjson.TypeReference;
34 public void test_1() throws Exception {
35 String input = "{'map':{}}";
36 DefaultExtJSONParser parser = new DefaultExtJSONParser(input, ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);
69 public void test_4() throws Exception {
70 String input = "{'map':{}}";
71 DefaultExtJSONParser parser = new DefaultExtJSONParser(input, ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);
73 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();
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));
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++) {
Bug_for_dragoon26.java (https://github.com/flydream/fastjson.git) Java · 175 lines
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));
72 MonitorConfigMessage message2 = (MonitorConfigMessage) JSON.parse(text);
73 System.out.println(JSON.toJSONString(message2, SerializerFeature.WriteClassName, SerializerFeature.PrettyFormat));
74 }
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();
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();
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;
7 import org.glassfish.jersey.client.ClientConfig;
8 import org.glassfish.jersey.server.JSONP;
9 import org.glassfish.jersey.server.ResourceConfig;
10 import org.glassfish.jersey.test.JerseyTest;
81 @Provider
82 static class FastJsonResolver implements ContextResolver<FastJsonConfig> {
84 public FastJsonConfig getContext(Class<?> type) {
86 FastJsonConfig fastJsonConfig = new FastJsonConfig();
88 fastJsonConfig.setSerializerFeatures(
ObjectFieldSerializer.java (https://github.com/flydream/fastjson.git) Java · 120 lines
14 * limitations under the License.
15 */
16 package com.alibaba.fastjson.serializer;
18 import java.util.Collection;
20 import com.alibaba.fastjson.annotation.JSONField;
21 import com.alibaba.fastjson.util.FieldInfo;
39 super(fieldInfo);
41 JSONField annotation = fieldInfo.getAnnotation(JSONField.class);
43 if (annotation != null) {
66 @Override
67 public void writeProperty(JSONSerializer serializer, Object propertyValue) throws Exception {
68 writePrefix(serializer);
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"
SerializeFilterable.java (https://github.com/alibaba/fastjson.git) Java · 271 lines
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, //
AwtCodec.java (https://github.com/alibaba/fastjson.git) Java · 350 lines
1 package com.alibaba.fastjson.serializer;
3 import java.awt.Color;
8 import java.lang.reflect.Type;
10 import com.alibaba.fastjson.JSON;
11 import com.alibaba.fastjson.JSONException;
12 import com.alibaba.fastjson.parser.DefaultJSONParser;
13 import com.alibaba.fastjson.parser.JSONLexer;
14 import com.alibaba.fastjson.parser.JSONToken;
15 import com.alibaba.fastjson.parser.ParseContext;
16 import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
18 public class AwtCodec implements ObjectSerializer, ObjectDeserializer {
Issue248_orderedField.java (https://github.com/alibaba/fastjson.git) Java · 81 lines
5 import org.junit.Assert;
7 import com.alibaba.fastjson.JSON;
8 import com.alibaba.fastjson.JSONObject;
9 import com.alibaba.fastjson.parser.Feature;
11 public class Issue248_orderedField extends TestCase {
72 Assert.assertEquals("k1",
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]);
79 }
ParserSpecialCharTest.java (https://github.com/alibaba/fastjson.git) Java · 95 lines
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 }
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);
Issue3448.java (https://github.com/alibaba/fastjson.git) Java · 89 lines
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);
59 List<List<String>> list = new ArrayList(4);
60 list.add(Collections.singletonList("item"));
61 String text = JSON.toJSONString(list);
62 System.out.println("text = " + text);
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;
12 import com.alibaba.fastjson.parser.ParserConfig;
13 import com.alibaba.fastjson.serializer.JSONSerializer;
14 import com.alibaba.fastjson.serializer.ObjectSerializer;
28 public FastjsonManualCodec(){
29 System.out.println("fastjson-" + JSON.VERSION);
31 serializeConfig.put(MediaContent.class, new MediaContentSerializer());
44 public <T> Collection<T> decodeArray(String text, Class<T> clazz) throws Exception {
45 DefaultJSONParser parser = new DefaultJSONParser(text, config);
46 parser.config(Feature.DisableCircularReferenceDetect, true);
47 return parser.parseArray(clazz);
JSONArray.java (https://github.com/flydream/fastjson.git) Java · 345 lines
19 import static com.alibaba.fastjson.util.TypeUtils.castToBigInteger;
20 import static com.alibaba.fastjson.util.TypeUtils.castToBoolean;
21 import static com.alibaba.fastjson.util.TypeUtils.castToByte;
26 import static com.alibaba.fastjson.util.TypeUtils.castToLong;
27 import static com.alibaba.fastjson.util.TypeUtils.castToShort;
28 import static com.alibaba.fastjson.util.TypeUtils.castToSqlDate;
40 import java.util.RandomAccess;
42 import com.alibaba.fastjson.util.TypeUtils;
44 /**
45 * @author wenshao<szujobs@hotmail.com>
46 */
47 public class JSONArray extends JSON implements List<Object>, JSONAware, Cloneable, RandomAccess, Serializable {
49 private static final long serialVersionUID = 1L;
TestFor_iteye_resolute.java (https://github.com/alibaba/fastjson.git) Java · 89 lines
1 package com.alibaba.json.test;
3 import java.io.Serializable;
8 import org.apache.commons.lang.SerializationUtils;
10 import com.alibaba.fastjson.JSON;
12 public class TestFor_iteye_resolute extends TestCase {
18 public void test_perf() {
19 for (int i = 0; i < 10; ++i) {
20 json();
21 javaSer();
22 System.out.println();
28 int length = 0;
29 for (int i = 0; i < LOOP_COUNT; ++i) {
30 String json = JSON.toJSONString(mkTestDates(SIZE));
31 length = json.length();
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());
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 {
25 try {
26 JSONSerializer serializer = new JSONSerializer(out);
27 serializer.getPropertyFilters().add(new PropertyFilter() {
PropertyFilter_long.java (https://github.com/alibaba/fastjson.git) Java · 149 lines
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);
46 SerializeWriter out = new SerializeWriter();
47 JSONSerializer serializer = new JSONSerializer(out);
48 serializer.getPropertyFilters().add(filter);
PropertyFilter_byte.java (https://github.com/alibaba/fastjson.git) Java · 149 lines
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);
46 SerializeWriter out = new SerializeWriter();
47 JSONSerializer serializer = new JSONSerializer(out);
48 serializer.getPropertyFilters().add(filter);
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 {
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;
JSONFieldDefaultValueTest.java (https://github.com/alibaba/fastjson.git) Java · 257 lines
1 package com.alibaba.json.bvt;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.annotation.JSONField;
8 public void test_default_value() throws Exception {
9 Model m = new Model();
10 String s = JSON.toJSONString(m);
11 System.out.println(s);
12 Model m2 = JSON.parseObject(s, Model.class);
32 public void test_not_null() throws Exception {
33 Model m = new Model("test", true, 888, (short)88, 'J', (byte)8, 8888L, 8.8F, 88.88, false, 999, (short)99, 'C', (byte)9, 9999L, 9.9F, 99.99);
34 String s = JSON.toJSONString(m);
35 System.out.println(s);
36 Model m2 = JSON.parseObject(s, Model.class);
64 @JSONField(defaultValue = "88") //shouldn't work
65 private short aShort;
66 @JSONField(defaultValue = "J") //shouldn't work
67 private char aChar;
68 @JSONField(defaultValue = "8") //shouldn't work
StringFieldTest_special_2.java (https://github.com/alibaba/fastjson.git) Java · 72 lines
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(">", ">");
59 model.name = buf.toString();
61 String text = JSON.toJSONString(model, SerializerFeature.BrowserCompatible);
63 Model model2 = JSON.parseObject(text, Model.class);
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;
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));
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());
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());
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;
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();
30 public void test_1() throws Exception {
31 String input = "{'map':null}";
32 DefaultExtJSONParser parser = new DefaultExtJSONParser(input, ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);
34 DefaultObjectDeserializer deser = new DefaultObjectDeserializer();
SendMsgHandler.java (https://gitlab.com/Mr.Tomato/linbox_server) Java · 207 lines
101 dao = sessionMessageDAO.insert(body);
103 logger.debug("Save SessionMessageDao into DB. Message: {}. Dao: {}", JSON.toJSONString(body), JSON.toJSONString(dao));
105 dispatcher.dispatchToSingle(remoteId, userId, sessionKey, MessageType.Session, body);
134 groupMsgDao = groupMessageDAO.insert(groupMsgBody);
136 logger.debug("Save GroupMessageDao into DB. Message: {}. Dao: {}", JSON.toJSONString(groupMsgBody), JSON.toJSONString(groupMsgDao));
138 dispatcher.dispatchToGroup(groupId, groupMsgBody);
140 } else {
141 logger.debug("Find existing GroupMessageDao for message: {}. Dao: {}", JSON.toJSONString(groupMsgBody), JSON.toJSONString(groupMsgDao));
142 }
JSONObjectTest3.java (https://github.com/alibaba/fastjson.git) Java · 182 lines
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();
94 Bean bean = JSON.parseObject(text, Bean.class);
96 JSONException error = null;
97 try {
98 bean.getA();
FastJsonSerializationTest.java (https://gitlab.com/zouxc/dubbo) Java · 266 lines
51 public void test_charArray() throws Exception {}
53 @Ignore("FastJson bug: com.alibaba.fastjson.JSONException: create asm serilizer error, class char")
54 @Test
55 public void test_charArray_withType() throws Exception {}
149 public void test_SPersonSet() throws Exception {}
151 @Ignore("FastJson bug: com.alibaba.fastjson.JSONException: illegal identifier : 1")
152 @Test
153 public void test_IntSPersonMap() throws Exception {}
248 public void test_PersonSet() throws Exception {}
250 @Ignore("FastJson bug: com.alibaba.fastjson.JSONException: illegal identifier : 1")
251 @Test
252 public void test_IntPersonMap() throws Exception {}
DataTransaction2.java (https://github.com/alibaba/fastjson.git) Java · 319 lines
10 import org.junit.Assert;
12 import com.alibaba.fastjson.JSON;
14 /**
285 }
287 public static DataTransaction2 fromJSON(String jsonString) {
288 return JSON.parseObject(jsonString, DataTransaction2.class);
299 System.out.println(dt.toJSON());
300 DataTransaction2 dt1 = JSON.parseObject(dt.toJSON(), DataTransaction2.class);
301 System.out.println(dt1.toJSON());
315 System.out.println(JSON.toJSONString(dt2));
317 Assert.assertEquals(dt.toJSON(), dt2.toJSON());
318 }
319 }
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) {
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)) {
FastjsonDataFormat.java (https://gitlab.com/matticala/apache-camel) Java · 188 lines
22 import java.util.List;
24 import com.alibaba.fastjson.JSON;
25 import com.alibaba.fastjson.serializer.SerializerFeature;
26 import com.alibaba.fastjson.support.config.FastJsonConfig;
27 import org.apache.camel.Exchange;
28 import org.apache.camel.Message;
33 /**
34 * A <a href="http://camel.apache.org/data-format.html">data format</a> ({@link DataFormat})
35 * using <a href="https://github.com/alibaba/fastjson">Fastjson</a> to marshal to and from JSON.
36 */
37 public class FastjsonDataFormat extends ServiceSupport implements DataFormat, DataFormatName {
53 }
55 public FastjsonDataFormat(FastJsonConfig config, Class<?> unmarshalType) {
56 this.config = config;
57 this.unmarshalType = unmarshalType;
NumberValueTest_error_13.java (https://github.com/alibaba/fastjson.git) Java · 409 lines
241 public void test_20() throws Exception {
242 JSONObject jsonObject = JSON.parseObject("{\"v\":49e99999999}");
243 Exception error = null;
244 try {
252 public void test_21() throws Exception {
253 JSONObject jsonObject = JSON.parseObject("{\"v\":49e99999999}");
254 Exception error = null;
255 try {
285 public void test_24() throws Exception {
286 JSONObject jsonObject = JSON.parseObject("{\"v\":49e99999999}");
287 Exception error = null;
288 try {
SymbolTableDupTest.java (https://github.com/alibaba/fastjson.git) Java · 108 lines
TypeUtilsTest_interface.java (https://github.com/alibaba/fastjson.git) Java · 136 lines
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 }
42 public void test_deser2() throws Exception {
43 JSON.parseObject("{\"id\":123}", new TypeReference<X_X<Integer>>(){});
44 }
Bug_for_BlankRain_Issue_502.java (https://github.com/alibaba/fastjson.git) Java · 107 lines
1 package com.alibaba.json.bvt.bug;
3 import java.util.ArrayList;
6 import org.junit.Assert;
8 import com.alibaba.fastjson.JSON;
10 import junit.framework.TestCase;
21 a1.set时间("F");
23 String text = JSON.toJSONString(a1);
24 Assert.assertEquals("{\"姓名\":\"A\",\"时间\":\"F\",\"满意度\":\"D\",\"状态\":\"C\",\"类型\":\"B\",\"统计\":\"E\"}", text);
25 System.out.println(text);
27 People a2 = JSON.parseObject(text, People.class);
28 Assert.assertEquals(a1.get姓名(), a2.get姓名());
29 Assert.assertEquals(a1.get类型(), a2.get类型());
LongTest_browserCompatible.java (https://github.com/alibaba/fastjson.git) Java · 70 lines
8 import org.junit.Assert;
10 import com.alibaba.fastjson.JSON;
11 import com.alibaba.fastjson.JSONObject;
12 import com.alibaba.fastjson.serializer.SerializerFeature;
14 import junit.framework.TestCase;
17 public void test_array() throws Exception {
18 long[] values = new long[] {Long.MIN_VALUE, -1, 0, 1, Long.MAX_VALUE};
19 String text = JSON.toJSONString(values, SerializerFeature.BrowserCompatible);
20 long[] values_2 = JSON.parseObject(text, long[].class);
30 StringWriter writer = new StringWriter();
31 JSON.writeJSONString(writer, values, SerializerFeature.BrowserCompatible);
32 String text = writer.toString();
33 long[] values_2 = JSON.parseObject(text, long[].class);
ListSerializer.java (https://bitbucket.org/xiejuntao/xdesktop.git) Java · 168 lines
14 * limitations under the License.
15 */
16 package com.alibaba.fastjson.serializer;
18 import java.io.IOException;
28 public static final ListSerializer instance = new ListSerializer();
30 public final void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType)
31 throws IOException {
JavaBeanSerializerTest.java (https://github.com/flydream/fastjson.git) Java · 215 lines
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());
FastJsonpHttpMessageConverter4Case1Test.java (https://github.com/alibaba/fastjson.git) Java · 167 lines
1 package com.alibaba.json.bvt.support.spring.mock.testcase;
3 import com.alibaba.fastjson.JSONObject;
4 import com.alibaba.fastjson.support.spring.FastJsonpResponseBodyAdvice;
60 mockMvc.perform(
61 (post("/fastjson/test1").characterEncoding("UTF-8").content(json.toJSONString())
62 .contentType(MediaType.APPLICATION_JSON))).andExpect(status().isOk()).andDo(print());
66 public void test1_2() throws Exception {
68 JSONObject json = new JSONObject();
70 json.put("id", 123);
74 ResultActions actions = mockMvc.perform((post("/fastjson/test1?callback=fnUpdateSome").characterEncoding(
75 "UTF-8").content(json.toJSONString()).contentType(MediaType.APPLICATION_JSON)));
76 actions.andDo(print());
77 actions.andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JAVASCRIPT));
DateTest.java (https://github.com/alibaba/fastjson.git) Java · 145 lines
10 import com.alibaba.fastjson.JSON;
11 import com.alibaba.fastjson.serializer.JSONSerializer;
12 import com.alibaba.fastjson.serializer.SerializeWriter;
13 import com.alibaba.fastjson.serializer.SerializerFeature;
15 public class DateTest extends TestCase {
33 SerializeWriter out = new SerializeWriter();
35 JSONSerializer serializer = new JSONSerializer(out);
36 serializer.config(SerializerFeature.UseISO8601DateFormat, true);
37 Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseISO8601DateFormat));
78 SerializeWriter out = new SerializeWriter();
80 JSONSerializer serializer = new JSONSerializer(out);
81 serializer.config(SerializerFeature.UseISO8601DateFormat, true);
82 Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseISO8601DateFormat));
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;
116 if (json.startsWith("{")) {
117 return JSON.parseObject(json, Map.class);
118 } else {
119 json = "{\"value\":" + json + "}";
120 Map<String, Object> map = JSON.parseObject(json, Map.class);
121 return map.get("value");
122 }
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
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 }
107 public void test_scan_new_12() throws Exception {
108 JSONScanner lexer = new JSONScanner("new\fa");
109 lexer.scanNullOrNew();
110 }
122 public void test_scan_new_15() throws Exception {
123 JSONScanner lexer = new JSONScanner("new]");
124 lexer.scanNullOrNew();
125 }
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());
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);
Issue2241.java (https://github.com/alibaba/fastjson.git) Java · 80 lines
1 package com.alibaba.json.bvt.issue_2200;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.annotation.JSONField;
24 assertEquals(1548166745000L, o.createTime.getTime());
26 String json = JSON.toJSONString(o);
27 assertEquals("{\"createTime\":1548166745}", json);
44 assertEquals(1531579788000L, o.createTime.getTimeInMillis());
46 String json = JSON.toJSONString(o);
47 assertEquals("{\"createTime\":\"20180714224948\"}", json);
54 assertEquals(1548166745L, o.createTime.toEpochSecond());
56 String json = JSON.toJSONString(o);
57 assertEquals("{\"createTime\":1548166745}", json);
DateTest_ISO8601_TimeZone.java (https://github.com/alibaba/fastjson.git) Java · 76 lines
12 import org.junit.Assert;
14 import com.alibaba.fastjson.JSON;
15 import com.alibaba.fastjson.TypeReference;
27 map.put("date", new Date(1425886057586l));
29 String json = JSON.toJSONString(map, SerializerFeature.UseISO8601DateFormat);
31 Assert.assertEquals("{\"date\":\"2015-03-09T15:27:37.586+08:00\"}", json);
41 VO v = new VO();
42 v.setGmtCreate(c);
43 String json = JSON.toJSONString(v, SerializerFeature.UseISO8601DateFormat);
44 System.out.println(json);
53 VO v = new VO();
54 v.setGmtCreate(c);
55 String json = JSON.toJSONString(v, SerializerFeature.UseISO8601DateFormat);
56 System.out.println(json);
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);
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;
DepartmentCodec.java (https://github.com/alibaba/fastjson.git) Java · 218 lines
3 import java.lang.reflect.Type;
5 import com.alibaba.fastjson.parser.DefaultJSONParser;
6 import com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask;
7 import com.alibaba.fastjson.parser.Feature;
8 import com.alibaba.fastjson.parser.JSONLexerBase;
9 import com.alibaba.fastjson.parser.JSONToken;
10 import com.alibaba.fastjson.parser.ParseContext;
11 import com.alibaba.fastjson.parser.ParserConfig;
12 import com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer;
13 import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
38 public Object deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
39 JSONLexerBase lexer = (JSONLexerBase) parser.getLexer();
41 if (lexer.isEnabled(Feature.SortFeidFastMatch)) {
LongTest2.java (https://github.com/alibaba/fastjson.git) Java · 90 lines
1 package com.alibaba.json.bvt.basicType;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONReader;
5 import com.alibaba.fastjson.parser.Feature;
6 import junit.framework.TestCase;
39 String json2 = "{\"v1\":\"-1883391953414482124\",\"v2\":\"-3019416596934963650\",\"v3\":\"6497525620823745793\",\"v4\":\"2136224289077142499\",\"v5\":\"-2090575024006307745\"}";
41 Model m1 = new JSONReader(new StringReader(json)).readObject(Model.class);
42 Model m2 = new JSONReader(new StringReader(json2)).readObject(Model.class);
64 Model m1 = new JSONReader(new StringReader(json), Feature.SupportArrayToBean).readObject(Model.class);
65 Model m2 = new JSONReader(new StringReader(json2), Feature.SupportArrayToBean).readObject(Model.class);
67 assertNotNull(m1);
TestUTF8_3.java (https://github.com/flydream/fastjson.git) Java · 221 lines
Bug_for_lenolix_8.java (https://github.com/alibaba/fastjson.git) Java · 112 lines
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);
43 Object object = JSON.parse(mapJson);
45 }
MetricsConvertUtils.java (https://github.com/didi/kafka-manager.git) Java · 203 lines
1 package com.xiaojukeji.kafka.manager.service.utils;
3 import com.alibaba.fastjson.JSON;
4 import com.xiaojukeji.kafka.manager.common.entity.dto.op.reassign.ReassignTopicDTO;
5 import com.xiaojukeji.kafka.manager.common.entity.metrics.BaseMetrics;
105 metricsDO.setClusterId(elem.getClusterId());
106 metricsDO.setTopicName(elem.getTopicName());
107 metricsDO.setMetrics(JSON.toJSONString(elem.getMetricsMap()));
108 doList.add(metricsDO);
109 }
127 metricsDO.setClusterId(elem.getClusterId());
128 metricsDO.setBrokerId(elem.getBrokerId());
129 metricsDO.setMetrics(JSON.toJSONString(elem.getMetricsMap()));
130 doList.add(metricsDO);
131 }
CaseAction.java (https://github.com/aaronchen2k/ngtesting-platform.git) Java · 249 lines
1 package com.ngtesting.platform.action.client;
3 import com.alibaba.fastjson.JSONObject;
4 import com.ngtesting.platform.action.BaseAction;
5 import com.ngtesting.platform.config.Constant;
56 @RequestMapping(value = "queryForSuiteSelection", method = RequestMethod.POST)
57 @PrivPrj(perms = {"test_case:view"})
58 public Map<String, Object> queryForSuiteSelection(HttpServletRequest request, @RequestBody JSONObject json) {
59 Map<String, Object> ret = new HashMap<String, Object>();
60 TstUser user = (TstUser) SecurityUtils.getSubject().getPrincipal();
197 @RequestMapping(value = "changeContentType", method = RequestMethod.POST)
198 @PrivPrj(perms = {"test_case:maintain"})
199 public Map<String, Object> changeContentType(HttpServletRequest request, @RequestBody JSONObject json) {
200 Map<String, Object> ret = new HashMap<String, Object>();
201 TstUser user = (TstUser) SecurityUtils.getSubject().getPrincipal();
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;
16 @NoArgsConstructor
17 public class WallResult {
18 @JSONField(name = "ResultCode")
19 private int ResultCode;
20 @JSONField(name = "Content")
24 @Data
25 public static class ContentBean {
26 @JSONField(name = "checkCount")
27 private int checkCount;
28 @JSONField(name = "hardCheckCount")
JsonIteratorImageTest.java (https://github.com/alibaba/fastjson.git) Java · 105 lines
1 package com.alibaba.json.test;
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONException;
5 import com.alibaba.fastjson.parser.DefaultJSONParser;
6 import com.alibaba.fastjson.parser.JSONLexerBase;
7 import com.alibaba.fastjson.parser.JSONToken;
8 import com.alibaba.fastjson.parser.ParserConfig;
9 import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
10 import com.jsoniter.JsonIterator;
76 return null;
77 }
78 JsonIteratorImageTest.Model obj = (com.jsoniter.CodegenAccess.existingObject(iter) == null ? new JsonIteratorImageTest.Model() : (JsonIteratorImageTest.Model)com.jsoniter.CodegenAccess.resetExistingObject(iter));
79 if (!com.jsoniter.CodegenAccess.readObjectStart(iter)) { return obj; }
GenerateJavaTest.java (https://github.com/alibaba/fastjson.git) Java · 110 lines
1 package com.alibaba.json.test;
3 import java.io.InputStream;
10 import org.apache.commons.io.IOUtils;
12 import com.alibaba.fastjson.JSON;
13 import com.alibaba.json.test.entity.Company;
23 protected void setUp() throws Exception {
24 InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/page_model_cached.json");
25 text = IOUtils.toString(is);
26 is.close();
105 }
107 String jsonString = JSON.toJSONString(group, true);
108 System.out.println(jsonString);
OptionalCodec.java (https://github.com/alibaba/fastjson.git) Java · 119 lines
1 package com.alibaba.fastjson.parser.deserializer;
3 import java.io.IOException;
8 import java.util.OptionalLong;
10 import com.alibaba.fastjson.JSONException;
11 import com.alibaba.fastjson.parser.DefaultJSONParser;
12 import com.alibaba.fastjson.parser.JSONToken;
13 import com.alibaba.fastjson.serializer.JSONSerializer;
14 import com.alibaba.fastjson.serializer.ObjectSerializer;
15 import com.alibaba.fastjson.util.TypeUtils;
21 @SuppressWarnings("unchecked")
22 public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
24 if (type == OptionalInt.class) {
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;
87 " }] ]\n" +
88 "}";
89 Object[] values = HSFJSONUtils.parseInvocationArguments(json, methodLocator);
90 assertNotNull(values);
91 assertEquals(2, values.length);
172 // System.out.println(json);
173 Object[] values = HSFJSONUtils.parseInvocationArguments(json, methodLocator);
174 assertNotNull(values);
175 assertEquals(1, values.length);
193 "}";
194 for (int i = 0; i < 1000 * 1000; ++i) {
195 Object[] values = HSFJSONUtils.parseInvocationArguments(json, methodLocator);
196 }
197 long millis = System.currentTimeMillis() - start;
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", "编辑中") {
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 }
JacksonGroupParser.java (https://github.com/alibaba/fastjson.git) Java · 301 lines
1 package com.alibaba.json.test.performance;
3 import java.io.IOException;
6 import java.util.List;
8 import com.alibaba.fastjson.JSONException;
9 import com.alibaba.json.test.entity.Company;
287 }
289 public static String getNextTextValue(String fieldName, JsonParser parser) throws JsonParseException, IOException {
290 JsonToken current = parser.nextToken(); // move to filed
296 }
298 public static void reportParseError(String errorMsg, JsonLocation jsonLoc) throws JsonParseException {
299 throw new JsonParseException(errorMsg, jsonLoc);
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);
JSONScannerTest_null.java (https://github.com/flydream/fastjson.git) Java · 126 lines
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 }
107 public void test_scan_null_12() throws Exception {
108 JSONScanner lexer = new JSONScanner("null\fa");
109 lexer.scanNullOrNew();
110 }
122 public void test_scan_false_15() throws Exception {
123 JSONScanner lexer = new JSONScanner("null]");
124 lexer.scanNullOrNew();
125 }
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;
14 @NoArgsConstructor
15 public class DataSourceResult {
16 @JSONField(name = "ResultCode")
17 private int ResultCode;
18 @JSONField(name = "Content")
24 private String serviceId;
26 @JSONField(name = "Identity")
27 private int Identity;
28 @JSONField(name = "Name")
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;
41 final JSONLexer lexer = parser.getLexer();
42 if (lexer.token() == JSONToken.LITERAL_INT) {
43 value = lexer.intValue();
44 lexer.nextToken(JSONToken.COMMA);
51 } else if (lexer.token() == JSONToken.LITERAL_STRING) {
52 String strVal = lexer.stringVal();
53 lexer.nextToken(JSONToken.COMMA);
55 if (strVal.length() == 0) {
DefaultExtJSONParser_parseArray.java (https://github.com/alibaba/fastjson.git) Java · 290 lines
12 import junit.framework.TestCase;
14 import com.alibaba.fastjson.JSON;
15 import com.alibaba.fastjson.JSONObject;
16 import com.alibaba.fastjson.TypeReference;
17 import com.alibaba.fastjson.parser.DefaultJSONParser;
18 import com.alibaba.fastjson.parser.Feature;
19 import com.alibaba.fastjson.parser.JSONToken;
21 public class DefaultExtJSONParser_parseArray extends TestCase {
108 JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
109 DefaultJSONParser parser = new DefaultJSONParser("\"2011-01-09T13:49:53.254\"");
110 parser.config(Feature.AllowISO8601DateFormat, true);
111 Object value = parser.parse();
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;
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);