提交 e1059911 编写于 作者: W wenshao

add testcase.

上级 cf5ba3a3
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;
}
}
}
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;
}
}
}
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;
}
}
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;
}
}
}
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);
}
}
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);
}
}
}
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 {
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册