Skip to content

Commit

Permalink
#Other fastjson中TypeReference的使用
Browse files Browse the repository at this point in the history
  • Loading branch information
duqi committed Oct 25, 2017
1 parent 3d4697b commit 69bda86
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/main/java/org/java/learn/TypeReferenceExample.java
@@ -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));
}
}

0 comments on commit 69bda86

Please sign in to comment.