AVRO can't encode json with array with different types

Viewed 114

I'm facing issue with avro. My goal is to create schema and encode json objects with avro. Issue is that my object can have multiple child objects which should be sambe "base class" but can be a bit different, and actually I have proper schema (or at least it seams that it is proper) but I'm getting ConfluentSchemaRegistryValidationError: invalid error while encoding object (I'm using nodejs).

Sample code:

{
  "namespace":"my.namespace",
  "type":"record",
  "name":"Obj1",
  "fields": [
    {
      "name":"type",
      "type":"string"
    },
    {
      "name":"categoryId",
      "type":"long"
    },
    {
      "name":"foo",
      "type":"string"    
    },
    {
      "name":"childEvents",
      "type": {
        "type": "array",
        "items": "null"
      }
    }
  ]
}
//====================================

{
  "namespace":"my.namespace",
  "type":"record",
  "name":"Obj2",
  "fields": [
    {
      "name":"type",
      "type":"string"
    },
    {
      "name":"categoryId",
      "type":"long"
    },
    {
      "name":"bar",
      "type":"string"    
    },
    {
      "name":"childEvents",
      "type": {
        "type": "array",
        "items": "null"
      }
    }
  ]
}
//====================================

{
  "namespace":"my.namespace",
  "type":"record",
  "name":"Obj3",
  "fields": [
    {
      "name":"type",
      "type":"string"
    },
    {
      "name":"categoryId",
      "type":"long"
    },
    {
      "name":"childEvents",
      "type": {
        "type": "array",
        "items": [
          "my.notification.Obj1",
          "my.notification.Obj2",
        ]
      }
    }
  ]
}

Any ideas?

0 Answers
Related