Skip to content

Commit

Permalink
add testcase for issue #1735
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Aug 14, 2023
1 parent 90a4b02 commit bea030b
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,37 @@
import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Test;

import java.nio.charset.StandardCharsets;

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

public class Issue1735 {
String str = "{\"DG_GridMain\":[{\"PKFIELDNAME\":1},{\"FIELDNAME\":2}]}";
String expected = "{\"DG_GridMain\":[{\"PKFIELDNAME\":1},{\"FIELDNAME\":2}]}";

@Test
public void test() {
Object object = JSON.parseObject(str);
assertEquals("{\"DG_GridMain\":[{\"PKFIELDNAME\":1},{\"FIELDNAME\":2}]}", JSON.toJSONString(object));
assertEquals(expected, JSON.toJSONString(object));
}

@Test
public void testBytesUTF8() {
byte[] bytes = str.getBytes();
Object object = JSON.parseObject(bytes, 0, bytes.length, StandardCharsets.UTF_8);
assertEquals(expected, JSON.toJSONString(object));
}

@Test
public void testBytes() {
Object object = JSON.parseObject(str.getBytes());
assertEquals("{\"DG_GridMain\":[{\"PKFIELDNAME\":1},{\"FIELDNAME\":2}]}", JSON.toJSONString(object));
public void testBytesLatin1() {
byte[] bytes = str.getBytes();
Object object = JSON.parseObject(bytes, 0, bytes.length, StandardCharsets.ISO_8859_1);
assertEquals(expected, JSON.toJSONString(object));
}

@Test
public void testChars() {
Object object = JSON.parseObject(str.toCharArray());
assertEquals("{\"DG_GridMain\":[{\"PKFIELDNAME\":1},{\"FIELDNAME\":2}]}", JSON.toJSONString(object));
assertEquals(expected, JSON.toJSONString(object));
}
}

0 comments on commit bea030b

Please sign in to comment.