-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix serialize String with '\n' unescaped, for issue #1387
- Loading branch information
Showing
2 changed files
with
29 additions
and
1 deletion.
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
28 changes: 28 additions & 0 deletions
28
core/src/test/java/com/alibaba/fastjson2/issues_1000/Issue1387.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,28 @@ | ||
package com.alibaba.fastjson2.issues_1000; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue1387 { | ||
@Test | ||
public void test() { | ||
String json = "{\"date\":\"2021\\nNOV\"}"; | ||
Bean params = JSON.parseObject(json, Bean.class); | ||
assertEquals(json, JSON.toJSONString(params)); | ||
assertEquals(json, new String(JSON.toJSONBytes(params))); | ||
} | ||
|
||
public static class Bean { | ||
private String date; | ||
|
||
public String getDate() { | ||
return date; | ||
} | ||
|
||
public void setDate(String date) { | ||
this.date = date; | ||
} | ||
} | ||
} |