比较并组合java中生成为JSON的两个对象

时间:2017-11-22 14:17:09

标签: java json spring-mvc

我有两个类型ClassA<List<List<String>>>的对象,它们从控制器重新作为JSON。我想基于两个属性(国家和运营商)合并这两个对象,如果它们相等的话。示例JSON看起来像

@RequestMapping(value = "/controller3"method= RequestMethod.GET produces= MediaType.APPLIACTION_JSON_VALUE)
public ClassA<List<List<String>>> process(HttpServletRequest request) {
    ClassA<List<List<String>>> one = service.getvalues();
    ClassA<List<List<String>>> two = service.getvaluestwo();
    return merge(one, two);
}

JSON1看起来像

  "title": "Source",
  "dateRange": "23 August 2017 - 21 November 2017",
  "total": 336,
  "pageSize": 336,
  "pageNum": -1,
  "nextPageKey": "",
  "results": [
    [
      "India",
      "Idea",
      "30"
    ],
    "headers": [
        "Country",
        "Operator",
        "Count"
  ]

JSON2看起来像

  "title": "Source",
  "dateRange": "23 August 2017 - 21 November 2017",
  "total": 336,
  "pageSize": 336,
  "pageNum": -1,
  "nextPageKey": "",
  "results": [
    [
      "India",
      "Idea",
      "20"
    ],
    "headers": [
        "Country",
        "Operator",
        "Count"
  ]

我希望从ClassA<List<List<String>>>类型的RestController中提取的结果JSON看起来像

  "title": "Source",
  "dateRange": "23 August 2017 - 21 November 2017",
  "total": 336,
  "pageSize": 336,
  "pageNum": -1,
  "nextPageKey": "",
  "results": [
    [
      "India",
      "Idea",
      "30",
      "20",
      "50"
    ],
    "headers": [
        "Country",
        "Operator",
        "Count1",
        "Count2",
        "Total"
  ]

如果没有匹配则将它们聚合为彼此零计数。 你能帮助我吗?

0 个答案:

没有答案