使用Spring的RestTemplate获取和映射JSON内部列表

问题描述 投票:0回答:1

我需要映射一个JSON对象,但问题是它有一个内部自定义列表。在这种情况下如何使用RestTemplate?

我正在尝试使用ResponseEntity和ParameterizedTypeReference,但我还没有找到解决方案。

{
   "results":{
      "ALL":{
         "currencyName":"Albanian Lek",
         "currencySymbol":"Lek",
         "id":"ALL"
      },
      "XCD":{
         "currencyName":"East Caribbean Dollar",
         "currencySymbol":"$",
         "id":"XCD"
      },
      "EUR":{
         "currencyName":"Euro",
         "currencySymbol":"€",
         "id":"EUR"
      },
      "BBD":{
         "currencyName":"Barbadian Dollar",
         "currencySymbol":"$",
         "id":"BBD"
      },
      "BTN":{
         "currencyName":"Bhutanese Ngultrum",
         "id":"BTN"
      },
      "BND":{
         "currencyName":"Brunei Dollar",
         "currencySymbol":"$",
         "id":"BND"
      },
      "XAF":{
         "currencyName":"Central African CFA Franc",
         "id":"XAF"
      },
      "CUP":{
         "currencyName":"Cuban Peso",
         "currencySymbol":"$",
         "id":"CUP"
      },
      "USD":{
         "currencyName":"United States Dollar",
         "currencySymbol":"$",
         "id":"USD"
      }
   }
}
json spring mapping custom-lists
1个回答
0
投票
// you can create a custom class like below and try to map it

class NodeWrapper{
  private Map<String, NodeData> results;
}

class NodeData{
   private String currencyName;
   private String currencySymbol;
   private id;
}


// also allow nulls using object mapper annotations
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.