enter image description hereGiven dynamic accountId return the onlineId and signinId for that specific user.

输入JSON:

[
  {
    "request": {
      "body": {
        "inputAccountId": "1234"
      }
    }
  },
  {
    "accountId": "1234",
    "ageGroup": 3,
    "role": 1,
    "gender": "f",
    "signinId": "aa@aa.com",
    "onlineId": "one"
  },
  {
    "accountId": "1122",
    "ageGroup": 3,
    "role": 2,
    "gender": "f",
    "signinId": "bb@aa.com",
    "onlineId": "two"
  },
  {
    "accountId": "2211",
    "ageGroup": 1,
    "role": 1,
    "gender": "f",
    "signinId": "cc@aa.com",
    "onlineId": "three"
  }
]

根据用例,如果accountId=1234accountId可以是任何帐户1122或2211,则返回该帐户ID的输出JSON.

-Jolt,来吧.

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "request": {
        "inputAccountId": "@(3,request.body.inputAccountId)"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "request": {
        "inputAccountId": "requestedId"
      },
      "1": {
        "*": {
          "accountId": {
            "requestedId": {
              "onlineId": "onlineId",
              "signinId": "signInId"
            }
          }
        }
      }
    }
  }
]

我无法使上面的代码正常工作.Java抛出错误- 读取jolt Spec文件时抛出"java.lang.NullPointerException".

我还try 了${qustedId},但它是数字的,所以我将其添加为请求ID,这会抛出nullPointer异常.

推荐答案

您可以使用以下转换规范:

[
  { // set values of the object keys to their accountIds
    // while taking out the value of request.body.inputAccountId
    "operation": "shift",
    "spec": {
      "*": {
        "request": {
          "body": {
            "inputAccountId": "inputId"
          }
        },
        "*": {
          "@": "@2,accountId.&"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "inputId": {
        "*": {
          "@2,&": "[]" // traverse 2 levels to reach 
                         // the value of "inputId" in order
                         // to match with the value of
                         // object keys
        }
      }
    }
  }
]

Java相关问答推荐

无法从TemporalAccessor获取Instant:{},ISO解析为2024-04- 25 T14:32:42类型为java.time. form.Parsed

伪类focus-in不适用于PFA中的选项卡

为什么我们仍然需要实现noArgsConstructor如果Java默认提供一个非参数化的构造函数?''

JavaFX Maven Assembly插件一直打包到错误的JDK版本

使用意向过滤器从另一个应用程序启动服务

我找不到&Quot;配置&的位置

当我已经安装了其他版本的Java时,如何在Mac OSX 14.3.1上安装Java 6?

Bean定义不是从Spring ApplationConext.xml文件加载的

使用Jolt将字段转换为列表

如何将其他属性引用到log4j2 yaml配置中?

在Java 15应用程序中运行Java脚本和Python代码

SpringBoot:在条件{Variable}.isBlank/{Variable}.isEmpty不起作用的情况下进行路径变量验证

使用SWIG将C++自定义单元类型转换为基本Java类型

在Oracle db中,当我们提供字符串而不是数字时,比较是如何工作的?

如何通过Java java.lang.Foreign API访问本机字节数组

未调用OnBackPressedCallback-Activitiy立即终止

我们可以在方法中声明接口吗?

OpenJDK20:JEP434:Foreign Function&;内存API(第二次预览)

带有提取器的JavaFXObservableList会根据侦听器的存在而改变行为

什么是;u〃;平均值;jdku;在java开发工具包中?