簡體   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