ObjectMapper mapper = new ObjectMapper(); User user = new User(); //Object to JSON in file mapper.writeValue(new File("c:\\user.json"), user); //Object to JSON in String String jsonInString = mapper.writeValueAsString(user); //Convert object to JSON string and pretty print String jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(user);
原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。