fix json bug

This commit is contained in:
Looly
2022-05-27 17:42:02 +08:00
parent 969a017f02
commit bfa130b564
7 changed files with 58 additions and 3 deletions

View File

@@ -0,0 +1,25 @@
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);
}
}