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
duqi
committed
Oct 25, 2017
1 parent
3d4697b
commit 69bda86
Showing
1 changed file
with
29 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.java.learn; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.TypeReference; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* 作用: User: duqi Date: 2017/10/25 Time: 13:42 | ||
*/ | ||
public class TypeReferenceExample { | ||
|
||
|
||
public static void main(String[] args) { | ||
Map<String, String> map = new HashMap<>(); | ||
map.put("key1", "value1"); | ||
map.put("key2", "value2"); | ||
map.put("key3", "value3"); | ||
|
||
System.out.println(JSON.toJSONString(map)); | ||
|
||
String jsonStr = JSON.toJSONString(map); | ||
|
||
Map<String, String> map2 = JSON.parseObject(jsonStr, new TypeReference<Map<String, String>>() { | ||
}); | ||
System.out.println(JSON.toJSONString(map2)); | ||
} | ||
} |