首页 > 解决方案 > Apache Nifi 验证嵌套 Json

问题描述

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

架构:

{
  "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]

我不明白这个消息。我想nested_field在 Json 中是有效的map,因此不应被处理器无效。我错过了什么?

编辑:* 删除了}示例 JSON。* Nifi-1.7.1,使用 JsonTreeReader 验证记录

标签: jsonvalidationavroapache-nifi

解决方案


找到NIFI-5678(确认存在错误)https://github.com/apache/nifi/pull/3060/commits/c66de368d07f37a8652c09e4b116b232972821ac已在版本 1.8.0 中发布。


推荐阅读