mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix byte[0]在json序列化时被忽略的bug;
This commit is contained in:
@@ -9,6 +9,7 @@ import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.json.test.bean.Price;
|
||||
import cn.hutool.json.test.bean.UserA;
|
||||
import cn.hutool.json.test.bean.UserC;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -244,10 +245,29 @@ public class JSONUtilTest {
|
||||
}
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
public void duplicateKeyTrueTest(){
|
||||
public void duplicateKeyTrueTest() {
|
||||
final String str = "{id:123, name:\"张三\", name:\"李四\"}";
|
||||
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(str, JSONConfig.create().setCheckDuplicate(true));
|
||||
Assert.assertEquals("{\"id\":123,\"name\":\"李四\"}", jsonObject.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试普通数组转JSONArray时是否异常, 尤其是byte[]数组, 可能是普通的byte[]数组, 也可能是二进制流
|
||||
*/
|
||||
@Test
|
||||
public void testArrayEntity() {
|
||||
final String jsonStr = JSONUtil.toJsonStr(new ArrayEntity());
|
||||
Assert.assertEquals("{\"a\":[],\"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];
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user