Apache Nifi验证嵌套Json

时间:2019-02-21 15:46:29

标签: json validation avro apache-nifi

我正在针对嵌套Json使用Avro模式使用Apache Nifi验证记录。我对JSON中的map字段有特殊的疑问。

模式:

{
  "type": "record",
  "name": "Test",
  "namespace": "test_events",
  "fields": [
    {
      "name": "id",
      "type": "string"
    },
    {
      "name": "test_attributes",
      "type": {
        "type": "record",
        "name": "test_attributes.instance",
        "fields": [
          {
            "name": "normal_field",
            "type": [
              "null",
              "string"
            ]
          },
          {
            "name": "nested_field",
            "type": [
              "null",
              {
                "type": "map",
                "values": [
                  "null",
                  "int"
                ]
              }
            ]
          }
        ]
      }
    }
  ]
}

Json数据:

{
  "id": "aplhanum123",
  "test_attributes": {
    "normal_field": "normal",
    "nested_field": {
      "meaning": 42
    }
  }
}

无效消息:

  

该FlowFile中的记录由于以下原因而无效:的   以下1个字段的值类型与架构不匹配:   [/ test_attributes / nested_field]

我不明白此消息。我以为Json中的nested_field是有效的map,因此处理器不应将其无效。我想念什么?

编辑:  *删除了示例JSON中的}。  * Nifi-1.7.1,使用JsonTreeReader进行ValidateRecord

1 个答案:

答案 0 :(得分:0)

使用NIFI-5678发现了https://github.com/apache/nifi/pull/3060/commits/c66de368d07f37a8652c09e4b116b232972821ac(已确认存在此错误)。