简体   繁体   English

颠簸转换取决于领域

[英]Jolt transformation depending on field

I have tried the following transformation spec:我尝试了以下转换规范:

[
  {
    "operation": "shift",
    "spec": {
      "response": {
        "success": {
          "true": {
            "#false": "error",
            "@(2,message)": "info_message",
            "series": "body.offer_series",
            "number": "body.offer_number",
            "end_date": "body.policy_end_date",
            "expiry_date": "body.offer_expiration_date",
            "commission": "body.commission.commission_amount",
            "premium_net": "body.premium.net_premium.amount",
            "total_premium": "body.premium.amount",
            "installments": {
              "*": {
                "number": "body.premium.installments[&1].number",
                "value": "body.premium.installments[&1].amount",
                "currency": "body.premium.installments[&1].currency",
                "due_date": "body.premium.installments[&1].due_date"
              }
            }
          },
          "false": {
            "*": {
              "*": "body.error_message"
            }
          }
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "body": {
        "good_id": "=toInteger"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "error_message": "=join(' | ',@(1,&))"
      }
    }
  }
]

in order to extract some fields from the request and the rest from the response.为了从请求中提取一些字段并从响应中提取 rest。 But no fields are displayed except the message and error.但是除了消息和错误之外,没有显示任何字段。 how should i write the spec in order to display all the fields depending the on the success of the call.我应该如何编写规范以根据调用的成功显示所有字段。

with the input for success = true :输入success = true

{
  "response": {
    "success": true,
    "data": {
      "series": "XX/32/V32/LM",
      "number": 8015,
      "end_date": "14/01/2024",
      "premium": 10192.05,
      "premium_net": 8969,
      "commission": 12,
      "installments": [
        {
          "number": 1,
          "value": 11007.41,
          "currency": "RON",
          "due_date": "05/01/2023"
        }
      ],
      "total_premium": 11007.41,
      "reference_premium": 1994,
      "direct_settlement_cover": 1,
      "direct_settlement": 815.36,
      "direct_settlement_net": 717.52,
      "bm": "B0",
      "exclusion_countries": [
        "BY",
        "IL",
        "IR",
        "MA",
        "RUS",
        "TN",
        "UA"
      ],
      "expiry_date": "04/02/2023",
      "appendix": false
    },
    "message": "Oferta a fost emisă cu succes"
  }
}

i would like to have the following output我想要以下output

{
  "error" : "false",
  "body" : {
    "offer_series" : "XX/32/V32/LM",
    "offer_number" : 8015,
    "policy_end_date" : "14/01/2024",
    "offer_expiration_date" : "04/02/2023",
    "commission" : {
      "commission_amount" : 12
    },
    "premium" : {
      "net_premium" : {
        "amount" : 8969
      },
      "amount" : 11007.41,
      "installments" : [ {
        "number" : 1,
        "amount" : 11007.41,
        "currency" : "RON",
        "due_date" : "05/01/2023"
      } ]
    }
  }
}

and for false the following:对于false以下内容:

input输入

{
  "response": {
    "success": false,
    "message": "Eroare validare date",
    "data": {
      "driver.0.name": [
        "Trebuie să menționați nume/denumire pentru șofer"
      ],
      "driver.1.name": [
        "Trebuie să menționați nume/denumire pentru șofer"
      ],
      "driver.1tin": [
        "CNP/CUI invalid pentru șofer"
      ],
      "vehicle.card": [
        "Serie CIV invalidă pentru vehiculul asigurat"
      ]
    }
  }
}

desired output需要 output

{
  "body" : {
    "info_message" : "Eroare validare date",
    "error_message" : "Trebuie să menționați nume/denumire pentru șofer | Trebuie să menționați nume/denumire pentru șofer | CNP/CUI invalid pentru șofer | Serie CIV invalidă pentru vehiculul asigurat"
  }
}

You can conditionally match the respective values of success within a shift transformation spec such as您可以有条件地匹配移位转换规范中的各个成功值,例如

[
  { 
    "operation": "shift",
    "spec": {
      "response": {
        "success": {
          "true": {
            "#false": "error",
            "@(2,data)": { //need to go two levels up the tree
              "series|number": "body.offer_&", // the "pipe" is the OR operator
              "end_date": "body.policy_&",
              "expiry_date": "body.offer_expiration_date",
              "comm*": "body.&.&_amount", // replicates the expression "commission" twice
              "*um_net": "body.&(0,1)um.net_&(0,1)um.amount", // &(0,1) -> replacement for the expression "premi" at the current level("0") of the first("1") asterisk
              "total_premium": "amount",
              "ins*": "body.&"
            }
          },
          "false": {
            // "@1": "&2",
            "@(2,message)": "body.info_message",
            "@(2,data)": {
              "*": {
                "*": "body.error_message"
              }
            }
          }
        }
      }
    }
  },
  { 
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "error_message": "=join(' | ',@(1,&))"
      }
    }
  }
]

the modify transformation will work only for the case success = false without any adverse impact on the other case.修改转换仅适用于success = false的情况,而不会对其他情况产生任何不利影响。

The demoes on the site http://jolt-demo.appspot.com/ are:网站http://jolt-demo.appspot.com/的演示是:

for the case success = true :对于案例success = true

在此处输入图像描述

for the case success = false :对于案例success = false

在此处输入图像描述

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM