Commit 05d40d89 authored by yanzg's avatar yanzg

升级新版本

parent 02ea3059
package helper;
import com.alibaba.fastjson.TypeReference;
import com.yanzuoguang.util.helper.JsonHelper;
import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
public class TestJsonHelper {
@Test
public void test() {
Fanxing<FanxingData> from = new Fanxing<>(new FanxingData("颜佐光"));
from.setList(null);
from.setListNull(null);
String json = JsonHelper.serialize(from);
Fanxing<FanxingData> to = JsonHelper.deserialize(json, new TypeReference<Fanxing<FanxingData>>() {
});
Assert.assertNotEquals(from, to);
Assert.assertNotEquals(from.getData(), to.getData());
Assert.assertEquals(from.getData().getName(), to.getData().getName());
Assert.assertFalse(to.getList() == null);
Assert.assertTrue(to.getListNull() == null);
}
@Test
public void test1() {
Fanxing<Fanxing<FanxingData>> from = new Fanxing<>(new Fanxing<>(new FanxingData("颜佐光")));
from.setList(null);
from.setListNull(null);
String json = JsonHelper.serialize(from);
Fanxing<Fanxing<FanxingData>> to = JsonHelper.deserialize(json, new TypeReference<Fanxing<Fanxing<FanxingData>>>() {
});
Assert.assertNotEquals(from, to);
Assert.assertNotEquals(from.getData(), to.getData());
Assert.assertEquals(from.getData().getData().getName(), to.getData().getData().getName());
Assert.assertFalse(to.getList() == null);
Assert.assertTrue(to.getListNull() == null);
}
}
class Fanxing<T> {
private T data;
/**
* null值反序列化后不会为null
*/
private List<T> list = new ArrayList<>();
/**
* null值反序列化后后会为null
*/
private List<T> listNull;
/**
* 当没有无参构造函数时无法序列化
*/
public Fanxing() {
}
public Fanxing(T data) {
this.data = data;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public List<T> getList() {
return list;
}
public void setList(List<T> list) {
this.list = list;
}
public List<T> getListNull() {
return listNull;
}
public void setListNull(List<T> listNull) {
this.listNull = listNull;
}
}
class FanxingData {
private String name;
/**
* 当没有无参构造函数时无法序列化
*/
public FanxingData() {
}
public FanxingData(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment