concat Jolt 转换在演示站点上有效;在代码中不起作用

concat Jolt transformation works on demo site; does not work in code

我想使用 Jolt(com.bazaarvoice.jolt:jolt-core:0.1.1com.bazaarvoice.jolt:json-utils:0.1.1)连接几个字段。这是一个示例输入记录:

{
  "ts": 1572873208.555711,
  "uid": "CQXg712bv3ayjojRwd",
  "orig_lat": 39.997,
  "orig_long": -105.0974,
  "resp_lat": 39.0481,
  "resp_long": -77.4728
}

...这是颠簸变换:

[
  {
    "operation": "modify-default-beta",
    "spec": {
      "orig_location": "=concat(@(1,orig_lat),',',@(1,orig_long))",
      "resp_location": "=concat(@(1,resp_lat),',',@(1,resp_long))"
    }
  }
]

... 这是 Jolt Transform Demo site:

转换的输出
{
  "ts" : 1.572873208555711E9,
  "uid" : "CQXg712bv3ayjojRwd",
  "orig_lat" : 39.997,
  "orig_long" : -105.0974,
  "resp_lat" : 39.0481,
  "resp_long" : -77.4728,
  "orig_location" : "39.997,-105.0974",
  "resp_location" : "39.0481,-77.4728"
}

我尝试以编程方式执行此操作:

String input = "{\"ts\":1572873208.555711,\"uid\":\"CQXg712bv3ayjojRwd\",\"orig_lat\":39.997,\"orig_long\":-105.0974,\"resp_lat\":39.0481,\"resp_long\":-77.4728}";

String JOLT_SPEC_LIST = "[\n" +
        "  {\n" +
        "    \"operation\": \"modify-default-beta\",\n" +
        "    \"spec\": {\n" +
        "      \"orig_location\": \"=concat(@(1,orig_lat),',',@(1,orig_long))\",\n" +
        "      \"resp_location\": \"=concat(@(1,resp_lat),',',@(1,resp_long))\"\n" +
        "    }\n" +
        "  }\n" +
        "]";

Chainr chainr = Chainr.fromSpec(JsonUtils.jsonToList(JOLT_SPEC_LIST));
Object transformed = chainr.transform(input);

transformed 对象应该包含转换后的输出。由于某种原因,输出与输入相同。它不包含两个派生字段。

你能看出我做错了什么吗?

我错误地将一个字符串传递给了转换方法。应该是 Object.

我使用 Jackson 将字符串转换为对象:

ObjectMapper mapper = new ObjectMapper();
Object inputObject = mapper.readValue(input, Object.class);

... 然后将该对象传递给 Chainr.transform() 方法。