Skip to content

Commit 69bda86

Browse files
author
duqi
committedOct 25, 2017
#Other fastjson中TypeReference的使用
1 parent 3d4697b commit 69bda86

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
 
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.java.learn;
2+
3+
import com.alibaba.fastjson.JSON;
4+
import com.alibaba.fastjson.TypeReference;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
9+
/**
10+
* 作用: User: duqi Date: 2017/10/25 Time: 13:42
11+
*/
12+
public class TypeReferenceExample {
13+
14+
15+
public static void main(String[] args) {
16+
Map<String, String> map = new HashMap<>();
17+
map.put("key1", "value1");
18+
map.put("key2", "value2");
19+
map.put("key3", "value3");
20+
21+
System.out.println(JSON.toJSONString(map));
22+
23+
String jsonStr = JSON.toJSONString(map);
24+
25+
Map<String, String> map2 = JSON.parseObject(jsonStr, new TypeReference<Map<String, String>>() {
26+
});
27+
System.out.println(JSON.toJSONString(map2));
28+
}
29+
}

0 commit comments

Comments
 (0)
Please sign in to comment.