This commit is contained in:
Looly
2022-06-10 22:57:15 +08:00
parent 54420d8429
commit d0ff3ab07b
4 changed files with 31 additions and 1 deletions

View File

@@ -1,3 +1,5 @@
package cn.hutool.json;
import cn.hutool.json.JSONUtil;
import lombok.Data;
import org.junit.Assert;

View File

@@ -0,0 +1,19 @@
package cn.hutool.json;
import org.junit.Assert;
import org.junit.Test;
public class Issue2369Test {
@Test
public void toJsonStrTest(){
//https://github.com/dromara/hutool/issues/2369
// byte[]数组对于JSONArray来说即可能是一个JSON字符串的二进制流也可能是普通数组因此需要做双向兼容
final byte[] bytes = {10, 11};
final String s = JSONUtil.toJsonStr(bytes);
Assert.assertEquals("[10,11]", s);
final Object o = JSONUtil.toBean(s, byte[].class, false);
Assert.assertArrayEquals(bytes, (byte[])o);
}
}