如下代码:
public class Main {
public class innerPerson{
private String name;
public String getName(){
return name;
}
}
public static void main(String[] args){
ObjectMapper om = new ObjectMapper();
Map map = new HashMap();
innerPerson one = new Main().new innerPerson();
one.name = "david";
innerPerson two = new Main().new innerPerson();
two.name = "saa";
innerPerson three = new Main().new innerPerson();
three.name = "yyy";
map.put(one, "david");
map.put(two, "11");
map.put(three, "true");
try {
String ans = om.writeValueAsString(map);
System.out.println(ans);
} catch (JsonGenerationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
输出为:
{"Main$innerPerson@12d15a9":"david","Main$innerPerson@10a3b24":"true","Main$innerPerson@e91f5d":"11"}
是否可以使地图的关键字是精确的数据,而不是对象的地址?怎么样?