This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3182 from CS304-mahoushoujyo/alibaba#3084
- Loading branch information
Showing
3 changed files
with
62 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
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
45 changes: 45 additions & 0 deletions
45
src/test/java/com/alibaba/fastjson/serializer/issue3084/TestRefWithQuote.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,45 @@ | ||
package com.alibaba.fastjson.serializer.issue3084; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.JSONObject; | ||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class TestRefWithQuote { | ||
|
||
public static class X { | ||
private String x; | ||
|
||
public X(String x) { | ||
this.x = x; | ||
} | ||
|
||
public String getX() { | ||
return x; | ||
} | ||
|
||
public void setX(String x) { | ||
this.x = x; | ||
} | ||
} | ||
|
||
@Test | ||
public void testIssue3084() { | ||
Map<String, TestRefWithQuote.X> origin = new HashMap<>(); | ||
TestRefWithQuote.X x = new TestRefWithQuote.X("x"); | ||
origin.put("aaaa\"", x); | ||
origin.put("bbbb\"", x); | ||
|
||
try { | ||
String json = JSON.toJSONString(origin, true); | ||
JSONObject root = JSON.parseObject(json); | ||
assertSame(root.get("bbbb\\"), root.get("aaaa\\")); | ||
} catch (Exception e) { | ||
fail("should not fail !!!"); | ||
} | ||
} | ||
} |