/**
* Json 示例
*/
public class JsonDemo {
private static Map<String,Object> map = new HashMap<>();
static {
map.put("id","");
map.put("name",null);
map.put("six",0);
map.put("address","xxx");
}
@Test
public void gsonTest(){
Gson gson = new Gson();
System.out.println(gson.toJson(map));
}
@Test
public void gsonBuilderTest(){
Gson gson = new GsonBuilder().serializeNulls().create();
System.out.println(gson.toJson(map));
}
@Test
public void jsonArrayTest(){
String s = JSONArray.toJSONString(map);
System.out.println(s);
}
@Test
public void jsonArrayTest2(){
String s = JSONArray.toJSONString(map, SerializerFeature.WriteMapNullValue);
System.out.println(s);
}
}