繁体   English   中英

摇晃如何在列表外包含对象并将其添加到列表的每个对象

[英]Jolt how to include object outside list and add it to each object of list

我有一个数组,我必须迭代并将列表外的对象附加到列表内的每个对象。 它没有正确发生。 由于产品是一个数组,如果每个对象有多个对象,我需要有该对象的 typeId。

请求

[
  {
    "offers": [
      {
        "type": {
          "id": "5"
        },
        "offerings": [
          {
            "id": "10"
          },
          {
            "id": "9"
          }
        ]
      },
      {
        "type": {
          "id": "3"
        },
        "offerings": [
          {
            "id": "11"
          }
        ]
      },
      {
        "type": {
          "id": "2"
        },
        "offerings": [
          {
            "id": "14"
          },
          {
            "id": "16"
          }
        ]
      }
    ]
  }
]

我的规格

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "offers": {
          "*": {
            "type": {
              "id": "[&4].[&2].typeId"
            },
            "offerings": {
              "*": {
                "id": "[&3].[&1].offerId"
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "[]"
      }
    }
  }
]

现在回复

[
  {
    "typeId": "5",
    "offerId": "10"
  },
  {
    "offerId": "9",
    "typeId": "3"
  },
  {
    "typeId": "2"
  },
  {
    "offerId": "11"
  },
  {
    "offerId": "14"
  },
  {
    "offerId": "16"
  }
]

预期

[
  {
    "typeId": "5",
    "offerId": "10"
  },
  {
    "typeId": "5",
    "offerId": "9"
  },
  {
    "typeId": "3",
    "offerId": "11"
  },
  {
    "typeId": "2",
    "offerId": "14"
  },
  {
    "typeId": "2",
    "offerId": "16"
  }
]

请帮助实现预期。

您可以将"id": "[&4].[&2].typeId"键值对"id": "[&4].[&2].typeId"到标记为"offerings"键名的对象中作为"@(2,type.id)": "[&3].[&1].typeid"以便根据需要组合它们,例如下面的

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "offerings": {
              "*": {
                "@(2,type.id)": "[&3].[&1].typeid",
                "*": "[&3].[&1].offer&"
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "[]"
      }
    }
   }
 ]

在此处输入图片说明

如何将元素添加到 Object,List 的 hashmap<object><div id="text_translate"><p> 我有一个来自 dao 的列表,我想把这个列表放在一个 HashMap&gt; 中,我的列表可以包含一个服务,它有多个参数,比如 serviceId=3。 在我的最终 HashMap 中,结果如下所示: {Service 1=[100,A],Service 2=[101,A],Service 3=[Parameter[102,B],Parameter[103,B],Parameter[104,C]]} 。</p><pre> serviceId paramId type 1 100 A 2 101 A 3 102 B 3 103 B 3 104 C</pre><p> 服务.java</p><pre> private int id; //Getters+Setters</pre><p> 参数.java</p><pre> private int id; private String type; //Getters+Setters</pre><p> 测试.java</p><pre> List result = dao.getServiceParam(); HashMap&lt;Service,List&lt;Parameter&gt;&gt; mapList = new HashMap&lt;Service, List&lt;Parameter&gt;&gt;(); if(.result;isEmpty()) { for (int i=0. i&lt; result;size(). i++) { Object[] line = (Object[])result;get(i); if ((BigDecimal) line[0]!=null) { } } }</pre></div></object>

[英]How to add element to hashmap of Object,List<Object>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java:将对象的每个实例的名称添加到列表中 如何在 Spring 中向对象添加列表 如何将对象添加到Java列表? 如何将对象数组添加到列表 如何在另一个列表对象内添加对象 如何将List <Future <Object >>添加到Set <Object>? 如何将元素添加到 Object,List 的 hashmap<object><div id="text_translate"><p> 我有一个来自 dao 的列表,我想把这个列表放在一个 HashMap&gt; 中,我的列表可以包含一个服务,它有多个参数,比如 serviceId=3。 在我的最终 HashMap 中,结果如下所示: {Service 1=[100,A],Service 2=[101,A],Service 3=[Parameter[102,B],Parameter[103,B],Parameter[104,C]]} 。</p><pre> serviceId paramId type 1 100 A 2 101 A 3 102 B 3 103 B 3 104 C</pre><p> 服务.java</p><pre> private int id; //Getters+Setters</pre><p> 参数.java</p><pre> private int id; private String type; //Getters+Setters</pre><p> 测试.java</p><pre> List result = dao.getServiceParam(); HashMap&lt;Service,List&lt;Parameter&gt;&gt; mapList = new HashMap&lt;Service, List&lt;Parameter&gt;&gt;(); if(.result;isEmpty()) { for (int i=0. i&lt; result;size(). i++) { Object[] line = (Object[])result;get(i); if ((BigDecimal) line[0]!=null) { } } }</pre></div></object> 动态修改列表以在列表的每个对象中添加新字段 如何添加数据以键入列表 <List<Object> &gt; 如何将对象列表添加到另一个列表中
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM