This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
7 changed files
with
298 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/test/java/com/alibaba/json/bvt/bug/Bug_for_yunban.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,62 @@ | ||
package com.alibaba.json.bvt.bug; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import junit.framework.TestCase; | ||
|
||
import java.util.HashMap; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class Bug_for_yunban extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
List<RelationItem> relationItemList = new LinkedList<RelationItem>(); | ||
|
||
Map<String, String> ext = new HashMap<String, String>(); | ||
ext.put("a", "b"); | ||
ext.put("c", "d"); | ||
|
||
|
||
RelationItem relationItem = new RelationItem(); | ||
relationItem.setExt(ext); | ||
relationItem.setSourceId("12"); | ||
relationItemList.add(relationItem); | ||
|
||
relationItem = new RelationItem(); | ||
relationItem.setExt(ext); | ||
relationItem.setSourceId("55"); | ||
relationItemList.add(relationItem); | ||
|
||
//ParserConfig.getGlobalInstance().setAutoTypeSupport(true); | ||
//String a = JSON.toJSONString(relationItemList, SerializerFeature.WriteClassName); | ||
String a1 = JSON.toJSONString(relationItemList); | ||
System.out.println(a1); | ||
|
||
|
||
//ParserConfig.getGlobalInstance().setAutoTypeSupport(true); | ||
List<RelationItem> relationItemList1 = JSON.parseObject(a1, new com.alibaba.fastjson.TypeReference<List<RelationItem>>(){}); | ||
|
||
System.out.print("fdafda"); | ||
} | ||
|
||
public static class RelationItem { | ||
private String sourceId; | ||
private Map<String, String> ext; | ||
|
||
public String getSourceId() { | ||
return sourceId; | ||
} | ||
|
||
public void setSourceId(String sourceId) { | ||
this.sourceId = sourceId; | ||
} | ||
|
||
public Map<String, String> getExt() { | ||
return ext; | ||
} | ||
|
||
public void setExt(Map<String, String> ext) { | ||
this.ext = ext; | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/test/java/com/alibaba/json/bvt/issue_1700/Issue1769.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,31 @@ | ||
package com.alibaba.json.bvt.issue_1700; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.annotation.JSONField; | ||
import com.alibaba.fastjson.annotation.JSONType; | ||
import junit.framework.TestCase; | ||
|
||
import java.util.Date; | ||
|
||
public class Issue1769 extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
byte[] newby = "{\"beginTime\":\"420180319160440\"}".getBytes(); | ||
QueryTaskResultReq rsp3 = JSON.parseObject(newby, QueryTaskResultReq.class); | ||
assertEquals("{\"beginTime\":\"152841225111920\"}", new String(JSON.toJSONBytes(rsp3))); | ||
} | ||
|
||
@JSONType(orders = {"beginTime"}) | ||
public static class QueryTaskResultReq | ||
{ | ||
private Date beginTime; | ||
|
||
@JSONField(format = "yyyyMMddHHmmss") | ||
public Date getBeginTime() { | ||
return beginTime; | ||
} | ||
|
||
public void setBeginTime(Date beginTime) { | ||
this.beginTime = beginTime; | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/test/java/com/alibaba/json/bvt/issue_1800/Issue1870.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,33 @@ | ||
package com.alibaba.json.bvt.issue_1800; | ||
|
||
import com.alibaba.fastjson.annotation.JSONField; | ||
import junit.framework.TestCase; | ||
|
||
import java.util.List; | ||
|
||
public class Issue1870 extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
|
||
} | ||
|
||
public static class Comment { | ||
@JSONField(name = "pic_arr") | ||
public List<Pic> pics; | ||
|
||
|
||
public List<Pic> getPics() { | ||
return pics; | ||
} | ||
|
||
public void setPics(List<Pic> pics) { | ||
this.pics = pics; | ||
} | ||
} | ||
|
||
public static class Pic { | ||
public int height; | ||
public String tburl; | ||
public String url; | ||
public String width; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/test/java/com/alibaba/json/bvt/issue_1800/Issue1871.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,47 @@ | ||
package com.alibaba.json.bvt.issue_1800; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.annotation.JSONField; | ||
import com.alibaba.fastjson.serializer.SerializerFeature; | ||
import junit.framework.TestCase; | ||
|
||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public class Issue1871 extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
UnwrapClass m = new UnwrapClass(); | ||
m.map = new HashMap(); | ||
m.name = "ljw"; | ||
m.map.put("a", "1"); | ||
m.map.put("b", "2"); | ||
|
||
String json = JSON.toJSONString(m, SerializerFeature.WriteClassName); | ||
System.out.println(json); | ||
} | ||
|
||
public static class UnwrapClass { | ||
|
||
private String name; | ||
|
||
@JSONField(unwrapped = true) | ||
private Map<String, String> map; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Map<String, String> getMap() { | ||
return map; | ||
} | ||
|
||
public void setMap(Map<String, String> map) { | ||
this.map = map; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/java/com/alibaba/json/bvt/issue_1800/Issue1892.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,24 @@ | ||
package com.alibaba.json.bvt.issue_1800; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.serializer.SerializerFeature; | ||
import junit.framework.TestCase; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class Issue1892 extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
assertEquals("\"2018-10-10T00:00:00\"", | ||
JSON.toJSONString( | ||
LocalDateTime.of(2018, 10, 10, 0, 0) | ||
) | ||
); | ||
} | ||
|
||
public void test_for_issue_1() throws Exception { | ||
String json = JSON.toJSONString( | ||
LocalDateTime.of(2018, 10, 10, 0, 0, 40, 788000000) | ||
); | ||
assertEquals("\"2018-10-10T00:00:40.788\"", json); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/test/java/com/alibaba/json/bvt/issue_1900/Issue1903.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,51 @@ | ||
package com.alibaba.json.bvt.issue_1900; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import junit.framework.TestCase; | ||
|
||
import java.beans.Transient; | ||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Proxy; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Issue1903 extends TestCase { | ||
public void test_issue() throws Exception { | ||
MapHandler mh = new MapHandler(); | ||
mh.add("name", "test"); | ||
mh.add("age", 20); | ||
|
||
Issues1903 issues = (Issues1903) Proxy.newProxyInstance(mh.getClass().getClassLoader(), new Class[]{Issues1903.class}, mh); | ||
System.out.println(issues.getName()); | ||
System.out.println(issues.getAge()); | ||
|
||
System.out.println(JSON.toJSON(issues).toString()); //正确结果: {"age":20} | ||
System.out.println(JSON.toJSONString(issues)); //正确结果: {"age":20} | ||
} | ||
|
||
interface Issues1903{ | ||
@Transient | ||
public String getName(); | ||
public void setName(String name); | ||
|
||
public Integer getAge(); | ||
public void setAge(Integer age); | ||
} | ||
|
||
|
||
class MapHandler implements InvocationHandler { | ||
Map<String, Object> map = new HashMap<String, Object>(); | ||
|
||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | ||
String name = method.getName().substring(3); | ||
String first = String.valueOf(name.charAt(0)); | ||
name = name.replaceFirst(first, first.toLowerCase()); | ||
return map.get(name); | ||
} | ||
|
||
public void add(String key, Object val){ | ||
map.put(key, val); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/test/java/com/alibaba/json/bvt/issue_1900/Issue1909.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,50 @@ | ||
package com.alibaba.json.bvt.issue_1900; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.JSONArray; | ||
import com.alibaba.fastjson.annotation.JSONField; | ||
import junit.framework.TestCase; | ||
|
||
import java.util.List; | ||
|
||
public class Issue1909 extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
JSONArray params = new JSONArray(); | ||
params.add("val1"); | ||
params.add(2); | ||
ParamRequest pr = new ParamRequest("methodName", "stringID", params); | ||
System.out.println(JSON.toJSONString(pr)); | ||
Request paramRequest = JSON.parseObject(JSON.toJSONString(pr), ParamRequest.class); | ||
} | ||
|
||
public static class ParamRequest extends Request { | ||
private String methodName; | ||
|
||
@JSONField(name = "id", ordinal = 3, serialize = true, deserialize = true) | ||
private Object id; | ||
|
||
private List<Object> params; | ||
|
||
public ParamRequest(String methodName, Object id, List<Object> params) { | ||
this.methodName = methodName; | ||
this.id = id; | ||
this.params = params; | ||
} | ||
|
||
public String getMethodName() { | ||
return methodName; | ||
} | ||
|
||
public Object getId() { | ||
return id; | ||
} | ||
|
||
public List<Object> getParams() { | ||
return params; | ||
} | ||
} | ||
|
||
public static class Request { | ||
|
||
} | ||
} |