Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,093 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.alibaba.json.bvt.bug; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.TypeReference; | ||
import junit.framework.TestCase; | ||
|
||
import java.io.Serializable; | ||
import java.lang.reflect.Type; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by wenshao on 02/07/2017. | ||
*/ | ||
public class Issue569 extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
String jsonString = "{\"backingMap\":{\"a\":{\"b\":{}}}}"; | ||
Type type = new TypeReference<MyTable<String, String, MyValue>>() {}.getType(); | ||
MyTable<String, String, MyValue> table = JSON.parseObject(jsonString, type); | ||
|
||
Map<String, MyValue> valueMap = table.backingMap.get("a"); | ||
assertNotNull(valueMap); | ||
|
||
MyValue value = valueMap.get("b"); | ||
assertNotNull(value); | ||
} | ||
|
||
public static class MyTable<R, C, V> implements Serializable { | ||
private Map<R, Map<C, V>> backingMap; | ||
|
||
public Map<R, Map<C, V>> getBackingMap() { | ||
return backingMap; | ||
} | ||
|
||
public void setBackingMap(Map<R, Map<C, V>> backingMap) { | ||
this.backingMap = backingMap; | ||
} | ||
} | ||
|
||
public static class MyValue { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.alibaba.json.bvt.emoji; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.serializer.SerializerFeature; | ||
import junit.framework.TestCase; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
|
||
/** | ||
* Created by wenshao on 13/04/2017. | ||
*/ | ||
public class EmojiTest0 extends TestCase { | ||
public void test_for_emoji() throws Exception { | ||
Model model = new Model(); | ||
model.value = "An 😀awesome 😃string with a few 😉emojis!"; | ||
|
||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
|
||
JSON.writeJSONString(out, model); | ||
|
||
String text = new String(out.toByteArray(), "UTF-8"); | ||
System.out.println(text); | ||
} | ||
|
||
public static class Model { | ||
public String value; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/java/com/alibaba/json/bvt/issue_1200/Issue1229.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.alibaba.json.bvt.issue_1200; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.JSONObject; | ||
import com.alibaba.fastjson.TypeReference; | ||
import junit.framework.TestCase; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by wenshao on 30/05/2017. | ||
*/ | ||
public class Issue1229 extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
final Object parsed = JSON.parse("{\"data\":{}}"); | ||
assertTrue(parsed instanceof JSONObject); | ||
assertTrue(((JSONObject)parsed).get("data") instanceof JSONObject); | ||
|
||
final Result<Data> result = JSON.parseObject("{\"data\":{}}", new TypeReference<Result<Data>>(){}); | ||
assertNotNull(result.data); | ||
assertTrue(result.data instanceof Data); | ||
|
||
final Result<List<Data>> result2 = JSON.parseObject("{\"data\":[]}", new TypeReference<Result<List<Data>>>(){}); | ||
assertNotNull(result2.data); | ||
assertTrue(result2.data instanceof List); | ||
assertEquals(0, result2.data.size()); | ||
} | ||
|
||
public void parseErr() throws Exception { | ||
JSON.parseObject("{\"data\":{}}", new TypeReference<Result<List<Data>>>(){}); | ||
fail("should be failed due to error json"); | ||
} | ||
|
||
public static class Result<T>{ | ||
T data; | ||
public void setData(T data) { | ||
this.data = data; | ||
} | ||
public T getData() { | ||
return data; | ||
} | ||
} | ||
|
||
public static class Data { | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
src/test/java/com/alibaba/json/bvt/issue_1200/Issue1233.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.alibaba.json.bvt.issue_1200; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.JSONObject; | ||
import com.alibaba.fastjson.parser.DefaultJSONParser; | ||
import com.alibaba.fastjson.parser.ParserConfig; | ||
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer; | ||
import junit.framework.TestCase; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by wenshao on 30/05/2017. | ||
*/ | ||
public class Issue1233 extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
ParserConfig.getGlobalInstance().putDeserializer(Area.class, new ObjectDeserializer() { | ||
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) { | ||
JSONObject jsonObject = (JSONObject) parser.parse(); | ||
String areaType; | ||
|
||
if (jsonObject.get("type") instanceof String) { | ||
areaType = (String) jsonObject.get("type"); | ||
} else { | ||
return null; | ||
} | ||
if (Area.TYPE_SECTION.equals(areaType)) { | ||
return (T) JSON.toJavaObject(jsonObject, Section.class); | ||
} else if (Area.TYPE_FLOORV1.equals(areaType)) { | ||
return (T) JSON.toJavaObject(jsonObject, FloorV1.class); | ||
} else if (Area.TYPE_FLOORV2.equals(areaType)) { | ||
return (T) JSON.toJavaObject(jsonObject, FloorV2.class); | ||
} | ||
return null; | ||
} | ||
|
||
public int getFastMatchToken() { | ||
return 0; | ||
} | ||
}); | ||
|
||
JSONObject jsonObject = JSON.parseObject("{\"type\":\"floorV2\",\"templateId\":\"x123\"}"); | ||
|
||
FloorV2 floorV2 = (FloorV2) jsonObject.toJavaObject(Area.class); | ||
assertNotNull(floorV2); | ||
assertEquals("x123", floorV2.templateId); | ||
} | ||
|
||
public interface Area { | ||
public static final String TYPE_SECTION = "section"; | ||
public static final String TYPE_FLOORV1 = "floorV1"; | ||
public static final String TYPE_FLOORV2 = "floorV2"; | ||
|
||
String getName(); | ||
} | ||
|
||
public static class Section implements Area { | ||
public List<Area> children; | ||
|
||
public String type; | ||
|
||
public String templateId; | ||
|
||
public String getName() { | ||
return templateId; | ||
} | ||
} | ||
|
||
public static class FloorV1 implements Area { | ||
public String type; | ||
public String templateId; | ||
|
||
public String getName() { | ||
return templateId; | ||
} | ||
} | ||
|
||
public static class FloorV2 implements Area { | ||
public List<Area> children; | ||
|
||
public String type; | ||
|
||
public String templateId; | ||
|
||
public String getName() { | ||
return templateId; | ||
} | ||
} | ||
} |
Oops, something went wrong.