Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-3188

Avro C++ library doesn't accept JSON without a field for union-type fields with default = null

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.10.2
    • None
    • c++
    • None
    • Debian

    Description

      We have a schema with a record with a union-type field with the "null" type being the first type and with a default value of `null`. When given a JSON datum without that field, decoding fails. I'd expect decoding to succeed with that field being given a value of `null`. Repro unit test to place in CodecTests.cc. (Apologies I can't get the code-formatting directives to work, so the code is a bit jumbled.)

      {{static void optionalFieldNotSupported() {
      const char *text = "

      {\"f1\": true }

      ";
      InputStreamPtr in =
      memoryInputStream(reinterpret_cast<const uint8_t *>(text),
      ::strlen(text));

      const char *schemaStr = "{\"type\":\"record\",\"name\":\"r\",\"fields\":["
      "

      {\"name\":\"f1\", \"type\":\"boolean\"}

      ,"
      "

      {\"name\":\"f2\", \"type\":[\"null\", \"long\"], \"default\": null}

      "
      "]}";
      ValidSchema schema = parsing::makeValidSchema(schemaStr);
      DecoderPtr d = jsonDecoder(schema);

      { d->init(*in); avro::GenericDatum datum(schema); avro::decode(*d, datum); }

      }}}

      Attachments

        Activity

          People

            Unassigned Unassigned
            pradn Prad Nelluru
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: