简体   繁体   English

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

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

I have an array which I have to iterate and append object that is outside the list to each of the object inside list.我有一个数组,我必须迭代并将列表外的对象附加到列表内的每个对象。 It is not happening properly.它没有正确发生。 Since offerings is an array if it has multiple objects to each object I need to have typeId of that object.由于产品是一个数组,如果每个对象有多个对象,我需要有该对象的 typeId。

Request :请求

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

My spec :我的规格

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

Response now :现在回复

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

Expected :预期

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

Please help to achieve as expected.请帮助实现预期。

You can transfer "id": "[&4].[&2].typeId" key-value pair into the object tagged "offerings" key name as "@(2,type.id)": "[&3].[&1].typeid" in order to combine them as desired such like the below one您可以将"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:将对象的每个实例的名称添加到列表中 - Java:Add name of each instance of object to list 如何在 Spring 中向对象添加列表 - How to add a list to an object in Spring 如何将对象添加到Java列表? - How to add an object to a Java List? 如何将对象数组添加到列表 - How to add array of object to the list 如何在另一个列表对象内添加对象 - How to Add an Object Inside Another List Object 如何将List <Future <Object >>添加到Set <Object>? - How to add List<Future<Object>> into 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> - How to add element to hashmap of Object,List<Object> 动态修改列表以在列表的每个对象中添加新字段 - Dynamically modify the list to add new field in each object of the list 如何添加数据以键入列表 <List<Object> &gt; - How to add data to type List<List<Object>> 如何将对象列表添加到另一个列表中 - how to add a list of object into another list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM