【问题标题】:How do I deserialize nested JSON using Spring restTemplate如何使用 Spring restTemplate 反序列化嵌套的 JSON
【发布时间】:2014-02-15 19:54:00
【问题描述】:

我浏览了Consuming a RESTful Web Service guide on the Spring website,但它没有谈论如何反序列化嵌套对象。例如,我将如何反序列化 sample 中的位置条目?

【问题讨论】:

    标签: json spring resttemplate


    【解决方案1】:

    您必须为作为顶级 Page 对象中的引用的 Location 数据创建域对象。下面是对这些类的过度简化的看法。您需要正确注释对象以按照您希望的方式序列化/反序列化,根据您使用的标记框架,有很多示例说明如何做到这一点。

    public class Page {
        String id;
        String about;
        ...
        Location location;
        ...
    }
    
    public class Location {
        String street;
        String city;
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 2020-09-10
      • 2013-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      • 2012-11-07
      相关资源
      最近更新 更多