1

I have a usecase where I need to have null values allowed for an Avro Map, but it seems like Avro doesn't allow unions for Map values. Basically, I need to implement the functionality of a POJO defined as Map<String,<Optional<String>>>.

How can I achieve this?

The following avro schema throws no type found error:

Error:
org.apache.avro:avro-maven-plugin:1.10.0: schema failed:
No type: {"type":["null","string"]}
{
    "namespace": "com.testclass.avro",
    "name": "test",
    "type": "record",
    "fields": [
        {
            "name": "user",
            "type": {
                "name": "userdetails",
                "type": "record",
                "fields": [
                    {
                        "name": "isPresent",
                        "type": "boolean"
                    },
                    {
                        "name": "address",
                        "type": {
                            "type": "map",
                            "name": "address",
                            "values": {
                                "type": ["null","string"]
                            }
                        }
                    }
                ]
            }
        }
    ]
}
Mehul
  • 47
  • 5

1 Answers1

0

Specifying the string as a string within the json definition helped solved the problem.

"address":{"test":{"string":"a"}, "test2":{"string":"a"}}
Mustafa Poya
  • 2,615
  • 5
  • 22
  • 36