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.
- Loading branch information
Showing
2 changed files
with
66 additions
and
2 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
63 changes: 63 additions & 0 deletions
63
src/test/java/com/alibaba/json/bvt/issue_1300/Issue1371.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,63 @@ | ||
package com.alibaba.json.bvt.issue_1300; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.serializer.SerializerFeature; | ||
import junit.framework.TestCase; | ||
import org.junit.Assert; | ||
|
||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
/** | ||
* Created by wenshao on 05/08/2017. | ||
*/ | ||
public class Issue1371 extends TestCase { | ||
private enum Rooms{ | ||
A, B, C, D ,E ; | ||
} | ||
|
||
public void testFastjsonEnum(){ | ||
|
||
Map<Rooms, Rooms> enumMap = new TreeMap<Rooms, Rooms>(); | ||
|
||
enumMap.put(Rooms.C, Rooms.D); | ||
enumMap.put(Rooms.E, Rooms.A); | ||
|
||
Assert.assertEquals(JSON.toJSONString(enumMap, SerializerFeature.WriteNonStringKeyAsString), | ||
"{\"C\":\"D\",\"E\":\"A\"}"); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
// public void testParsed(){ | ||
// | ||
// String oldStyleJson = "{1:'abc', 2:'cde'}"; | ||
// | ||
// Gson gson = new Gson(); | ||
// | ||
// Map fromJson = gson.fromJson(oldStyleJson, Map.class); | ||
// | ||
// Assert.assertNull(fromJson.get(1)); | ||
// | ||
// Assert.assertEquals(fromJson.get("1"), "abc" ); | ||
// | ||
// Map parsed = JSON.parseObject(oldStyleJson, Map.class, Feature.IgnoreAutoType, Feature.DisableFieldSmartMatch); | ||
// | ||
// | ||
// Assert.assertNull(parsed.get(1)); | ||
// | ||
// Assert.assertEquals(parsed.get("1"), "abc" ); | ||
// | ||
// } | ||
// | ||
// public void testParsed_jackson() throws Exception { | ||
// | ||
// String oldStyleJson = "{1:\"abc\", 2:\"cde\"}"; | ||
// | ||
// ObjectMapper objectMapper = new ObjectMapper(); | ||
// Map fromJson = objectMapper.readValue(oldStyleJson, Map.class); | ||
// Assert.assertNull(fromJson.get(1)); | ||
// } | ||
} |