Skip to content

Commit

Permalink
feat add testcases for issue alibaba#1828 and alibaba#1874
Browse files Browse the repository at this point in the history
  • Loading branch information
yanxutao89 authored and wenshao committed Sep 25, 2023
1 parent d2694b4 commit 3af27dd
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.alibaba.fastjson2.issues_1800;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import lombok.Data;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class Issue1828 {
private static final int SIZE = 50 * 1024 * 1024;

@Test
public void test() {
DTO dto = new DTO();
dto.setVedioBytes(new byte[SIZE]);
String json = JSON.toJSONString(dto, JSONWriter.Feature.LargeObject);
assertEquals(SIZE, JSON.parseObject(json, DTO.class).getVedioBytes().length);
}

@Data
public class DTO {
private byte[] vedioBytes;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.alibaba.fastjson2.issues_1800;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.*;

public class Issue1874 {
@Test
public void test() {
List<TestJson> list = new ArrayList<>();
list.add(new TestJson(true, Boolean.FALSE));
list.add(new TestJson(false, Boolean.TRUE));
String json = JSON.toJSONString(list, JSONWriter.Feature.WriteBooleanAsNumber);
assertEquals("[{\"b\":1,\"b2\":0},{\"b\":0,\"b2\":1}]", json);
List<TestJson> list2 = JSON.parseArray(json, TestJson.class);
assertEquals(list, list2);
}

@Data
@AllArgsConstructor
public static class TestJson {
private boolean b;
private Boolean b2;
}
}

0 comments on commit 3af27dd

Please sign in to comment.