mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add test
This commit is contained in:
parent
e85bd4ada4
commit
7ea286cb29
@ -8,6 +8,7 @@ import cn.hutool.json.serialize.JSONString;
|
|||||||
import cn.hutool.json.test.bean.Price;
|
import cn.hutool.json.test.bean.Price;
|
||||||
import cn.hutool.json.test.bean.UserA;
|
import cn.hutool.json.test.bean.UserA;
|
||||||
import cn.hutool.json.test.bean.UserC;
|
import cn.hutool.json.test.bean.UserC;
|
||||||
|
import lombok.Data;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -247,4 +248,23 @@ public class JSONUtilTest {
|
|||||||
final String s = JSONUtil.toJsonStr(a);
|
final String s = JSONUtil.toJsonStr(a);
|
||||||
Assert.assertEquals("1", s);
|
Assert.assertEquals("1", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试普通数组转JSONArray时是否异常, 尤其是byte[]数组, 可能是普通的byte[]数组, 也可能是二进制流
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testArrayEntity() {
|
||||||
|
final String jsonStr = JSONUtil.toJsonStr(new ArrayEntity());
|
||||||
|
// a为空的bytes数组,按照空的流对待
|
||||||
|
Assert.assertEquals("{\"b\":[0],\"c\":[],\"d\":[],\"e\":[]}", jsonStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
static class ArrayEntity {
|
||||||
|
private byte[] a = new byte[0];
|
||||||
|
private byte[] b = new byte[1];
|
||||||
|
private int[] c = new int[0];
|
||||||
|
private Byte[] d = new Byte[0];
|
||||||
|
private Byte[] e = new Byte[1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user