You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Anton Kondratev (Jira)" <ji...@apache.org> on 2021/12/21 20:31:00 UTC
[jira] [Commented] (AVRO-3188) Avro C++ library doesn't accept JSON without a field for union-type fields with default = null
[ https://issues.apache.org/jira/browse/AVRO-3188?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17463457#comment-17463457 ]
Anton Kondratev commented on AVRO-3188:
---------------------------------------
Hi [~pradn], in my case even serialization doesn't work when I have optional field in schema (\{"name": "somefield", type": ["null", "string"], "defaults": null}) and nonempty corresponding field in json-data ("somefield":"somedata"). I'm using 1.10.2 version too. Do you have such problem?
> Avro C++ library doesn't accept JSON without a field for union-type fields with default = null
> ----------------------------------------------------------------------------------------------
>
> Key: AVRO-3188
> URL: https://issues.apache.org/jira/browse/AVRO-3188
> Project: Apache Avro
> Issue Type: Bug
> Components: c++
> Affects Versions: 1.10.2
> Environment: Debian
> Reporter: Prad Nelluru
> Priority: Minor
>
> 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);
> }
> }}}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)