使用jaxkson将对象转换成json/xml字符串
发布日期:2021-05-08 20:43:25 浏览次数:20 分类:精选文章

本文共 619 字,大约阅读时间需要 2 分钟。

import org.codehaus.jackson.map.ObjectMapper;import com.fasterxml.jackson.xml.XmlMapper;public class Foo{     public String name;  public Bar bar;  public static void main(String[] args) throws Exception  {       // JSON input: {"name":"FOO","bar":{"id":42}}    String jsonInput = "{\"name\":\"FOO\",\"bar\":{\"id\":42}}";    ObjectMapper jsonMapper = new ObjectMapper();    Foo foo = jsonMapper.readValue(jsonInput, Foo.class);    XmlMapper xmlMapper = new XmlMapper();    System.out.println(xmlMapper.writeValueAsString(foo));    // 
FOO
42
}}class Bar{ public int id;}
上一篇:springmvc的RequestMapping中的produces与consumes指定http的请求格式和返回格式
下一篇:java8中的闭包Function/BiFunction

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年03月27日 10时25分17秒