阅读背景:

我们可以在使用JSON时将对象设置为地图中的键吗?

来源:互联网 

As the code below:

如下面的代码:

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<innerPerson, String> map = new HashMap<innerPerson,String>();

        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();
        }

    }

}
public class Mai



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: