jackson-dataformats-binary icon indicating copy to clipboard operation
jackson-dataformats-binary copied to clipboard

Cannot find method to generate AVRO schema will nullable Map values

Open DominicDeCesare-Capita opened this issue 5 years ago • 3 comments

This class when Avro'd

public final class Foo {
    private Map<String, String> strings;

    public Map<String, String> getStrings() {
        return strings;
    }

    public void setStrings( Map<String, String> strings ) {
        this.strings = strings;
    }

Results in this schema:

{
  "type" : "record",
  "name" : "Foo",
  "namespace" : "my.package",
  "doc" : "Schema for my.package",
  "fields" : [ {
    "name" : "strings",
    "type" : [ "null", {
    "type" : "map",
    "values" : "string"
  } ]
}

Where as I want this schema:


{
  "type" : "record",
  "name" : "Foo",
  "namespace" : "my.package",
  "doc" : "Schema for my.package",
  "fields" : [ {
    "name" : "strings",
    "type" : [ "null", {
    "type" : "map",
    "values" :  [ "null", "string" ]
  } ]
}

I can't see a way to do this currently.

DominicDeCesare-Capita avatar Dec 07 '18 16:12 DominicDeCesare-Capita

I've gone with programmatically editing the result schema to make the map values nullable as a workaround for now.

DominicDeCesare-Capita avatar Dec 17 '18 10:12 DominicDeCesare-Capita

@DominicDeCesare-Capita please include a reproduction of what you are doing, how: unfortunately description is bit unclear on what exactly is happening.

cowtowncoder avatar Dec 19 '18 19:12 cowtowncoder

Actually I think description is ok. So basically String values here should be indicated to be "optional" (String OR null), not mandatory.

cowtowncoder avatar Aug 30 '19 04:08 cowtowncoder