【问题标题】:Jolt Spec for Shift Operation换档操作的颠簸规范
【发布时间】:2020-04-23 13:50:43
【问题描述】:

我有以下 JSON 输入

{
  "Status": "PENDING",
  "TaskId": "0000000001",
  "EventType": "change",
  "Timestamp": "2019-01-09-15.41.57.473940T01",
  "Comment": "{\"comment\":[{\"createDate\":\"2019-01-09T15:41:57:473000-05:00\",\"type\":\"system\",\"text\":\"Assigned to: RAJ\",\"userId\":\"RAJ\",\"userName\":\"RAJA MADHIE\"},{\"createDate\":\"2019-01-09T15:45:59:150000-05:00\",\"type\":\"manual\",\"text\":\"Comments entered for 0000000001\",\"userId\":\"RAJ\",\"userName\":\"RAJA MADHIE\"},{\"createDate\":\"2019-01-09T15:49:09:586000-05:00\",\"type\":\"manual\",\"text\":\"Comments entered for 0000000001 - processed.\",\"userId\":\"RAJ\",\"userName\":\"RAJA MADHIE\"}]}"
}

并期望输出类似于:

{
  "inputs": [
    {
      "richInput": {
        "subjectId": "0000000001",
        "body": {
          "messageSegments": [
            {
              "type": "system",
              "text": "Assigned to: RAJ"
            }
          ]
        },
        "feedElementType": "FeedItem"
      }
    },
    {
      "richInput": {
        "subjectId": "0000000001",
        "body": {
          "messageSegments": [
            {
              "type": "manual",
              "text": "Comments entered for 0000000001"
            }
          ]
        },
        "feedElementType": "FeedItem"
      }
    },
    {
      "richInput": {
        "subjectId": "0000000001",
        "body": {
          "messageSegments": [
            {
              "type": "manual",
              "text": "Comments entered for 0000000001-processed."
            }
          ]
        },
        "feedElementType": "FeedItem"
      }
    }
  ]
}

我尝试使用几个 JOLT 规格来改变它,但没有运气......任何建议或建议都非常感谢。谢谢!

【问题讨论】:

  • Comment 属性是 string 而不是 JSON ObjectJOLT 不会处理这种情况。你需要反序列化这个string,转换并序列化为JSON。您可以为此使用Jackson
  • @MichałZiober 谢谢!除了杰克逊还有其他工作吗?
  • 你能把你的 JOLT 规格放在这里吗?

标签: apache-nifi jolt


【解决方案1】:

你需要让 cmets 成为一个合适的 JSON 结构,它会如下所示。

{
 "Status": "PENDING",
 "TaskId": "0000000001",
 "EventType": "change",
 "Timestamp": "2019-01-09-15.41.57.473940T01",
 "Comment": {
   "comment": [
    {
      "createDate": "2019-01-09T15:41:57:473000-05:00",
      "type": "system",
      "text": "Assigned to: RAJ",
      "userId": "RAJ",
      "userName": "RAJA MADHIE"
    },
    {
      "createDate": "2019-01-09T15:45:59:150000-05:00",
      "type": "manual",
      "text": "Comments entered for 0000000001",
      "userId": "RAJ",
      "userName": "RAJA MADHIE"
    },
    {
      "createDate": "2019-01-09T15:49:09:586000-05:00",
      "type": "manual",
      "text": "Comments entered for 0000000001 - processed.",
      "userId": "RAJ",
      "userName": "RAJA MADHIE"
     }
   ]
 }
}

用于转换的规范文件:

[
{
"operation": "shift",
"spec": {
  "Comment": {
    "comment": {
      "*": {
        "@(3,TaskId)": "inputs[&1].richInput.subjectId",
        "type": "inputs[&1].richInput.body.messageSegments[0].type",
        "text": "inputs[&1].richInput.body.messageSegments[0].text",
        "#FeedItem": "inputs[&1].richInput.feedElementType"
      }
    }
  }
}
},
{
"operation": "shift",
"spec": {
  "inputs": {
    "*": {
        "richInput": {
          "subjectId": "inputs[&2].richInput.subjectId",
          "body": "inputs[&2].richInput.body",
          "feedElementType": "inputs[&2].richInput.feedElementType"
         }
       }
     }
   }
  }
]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多