-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix serialize special string, for issue #1025
- Loading branch information
Showing
4 changed files
with
60 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
core/src/test/java/com/alibaba/fastjson2/issues_1000/Issue1025.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.alibaba.fastjson2.issues_1000; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue1025 { | ||
@Test | ||
public void test2000() throws Exception { | ||
byte[] bytes = new byte[8000]; | ||
Arrays.fill(bytes, (byte) 'A'); | ||
for (int i = 0; i < 2000; i++) { | ||
bytes[i] = 0x01; | ||
} | ||
|
||
String str = new String(bytes, "UTF-8"); | ||
String json = JSON.toJSONString(str); | ||
assertEquals(str, JSON.parse(json)); | ||
|
||
byte[] jsonBytes = JSON.toJSONBytes(str); | ||
assertEquals(str, JSON.parse(jsonBytes)); | ||
} | ||
|
||
@Test | ||
public void test4000() throws Exception { | ||
byte[] bytes = new byte[8000]; | ||
Arrays.fill(bytes, (byte) 'A'); | ||
for (int i = 1000; i < 5000; i++) { | ||
bytes[i] = 0x01; | ||
} | ||
|
||
String str = new String(bytes, "UTF-8"); | ||
String json = JSON.toJSONString(str); | ||
assertEquals(str, JSON.parse(json)); | ||
|
||
byte[] jsonBytes = JSON.toJSONBytes(str); | ||
assertEquals(str, JSON.parse(jsonBytes)); | ||
} | ||
} |