fix json bug

This commit is contained in:
Looly
2022-05-27 17:55:37 +08:00
parent 66fe842140
commit 55923c4af2
6 changed files with 61 additions and 8 deletions

View File

@@ -0,0 +1,24 @@
package cn.hutool.json;
import org.junit.Assert;
import org.junit.Test;
public class IssueI59LW4Test {
@Test
public void bytesTest(){
final JSONObject jsonObject = JSONUtil.createObj().set("bytes", new byte[]{1});
Assert.assertEquals("{\"bytes\":\"AQ==\"}", jsonObject.toString());
final byte[] bytes = jsonObject.getBytes("bytes");
Assert.assertArrayEquals(new byte[]{1}, bytes);
}
@Test
public void bytesInJSONArrayTest(){
final JSONArray jsonArray = JSONUtil.createArray().set(new byte[]{1});
Assert.assertEquals("[\"AQ==\"]", jsonArray.toString());
final byte[] bytes = jsonArray.getBytes(0);
Assert.assertArrayEquals(new byte[]{1}, bytes);
}
}