Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avro::decode not able to handle NULL array. Thows "Incorrect token in the stream. Expected: Array start, found Null" #49

Open
bhuvanracham opened this issue Jul 1, 2022 · 0 comments

Comments

@bhuvanracham
Copy link

The serdes CPP code is not able to handle NULL arrays when converting json to avro.

sample excerpt of input json that fails:
,"list1":[{"test1", "test2"}],"list2":null,"listItemCount":0,.........

It bails out at "avro::decode(*json_decoder, *datum);" while handling list2. How can we make decode accept null values which could be valid in some cases. Same question applies to a record that could be null too. Thanks.

static int
Json2Avro(Serdes::Schema *schema, const std::string &json, avro::GenericDatum **datump)
{
avro::ValidSchema *avro_schema = schema->object();

std::istringstream iss(json);
auto json_is = avro::istreamInputStream(iss);
avro::DecoderPtr json_decoder = avro::jsonDecoder(*avro_schema);
avro::GenericDatum *datum = new avro::GenericDatum(*avro_schema);

try {
    json_decoder->init(*json_is);
    avro::decode(*json_decoder, *datum);
}
catch (const avro::Exception &ex) {
    cerr << "JSON to avro transformation failed: " << ex.what() << endl;
    return -1;
}

*datump = datum;

return 0;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant