【问题标题】:Jolt: Conditional placing value if boolean is trueJolt:如果布尔值为真,则有条件放置值
【发布时间】:2022-01-24 17:40:24
【问题描述】:

我有这种情况,如果 defaultshipping 为 true,则应将电话放入 shippingAddressBook->phone 中(与计费相同)。我的转变很接近了,但问题是它没有抓住“电话”的价值。

有人可以帮我解决这个问题吗:)

输入:

{
  "phone": "869-947-4444",
  "defaultshipping": false,
  "defaultbilling": true
}

预期输出:

{
  "billingAddressBook" : {
    "phone" : "869-947-4444"
  }
}

我的转型尝试:

[
  {
    "operation": "shift",
    "spec": {
      "defaultbilling": {
        "true": {
          "#phone": "billingAddressBook.phone"
        }
      },
      "defaultshipping": {
        "true": {
          "#phone": "shippingAddressBook.phone"
        }
      }
    }
  }
]

【问题讨论】:

    标签: java json jolt


    【解决方案1】:

    是的,你已经很接近了,只需要升2级就可以达到phone的水平,并通过使用@(2,phone)来获取价值,例如

    [
      {
        "operation": "shift",
        "spec": {
          "defaultbilling": {
            "true": {
              "@(2,phone)": "billingAddressBook.phone"
            }
          },
          "defaultshipping": {
            "true": {
              "@(2,phone)": "shippingAddressBook.phone"
            }
          }
        }
      }
    ]
    

    【讨论】:

    • 再次感谢巴巴罗斯!!如果我们在数组中有相同的输入,你知道如何适应这个: [ {phone, defaultS, defaultB}, {phone, defaultS, defaultB},... ] 将相同的转换逻辑应用于每个成员。
    • 不客气@NicolasJimenez 学习很好!如果您使用额外的大括号(例如 "spec": {"*": { the same as above }} 其中示例输入为 [ { "phone": "869-947-4444", "defaultshipping": false, "defaultbilling": true }, { "phone": "132-865-2222", "defaultshipping": true, "defaultbilling": false } ]
    猜你喜欢
    • 2014-01-24
    • 2022-08-15
    • 1970-01-01
    • 2012-02-23
    • 2016-10-13
    • 2014-04-25
    • 2020-10-07
    • 1970-01-01
    • 2012-06-28
    相关资源
    最近更新 更多