diff --git a/atdcpp/test/cpp-expected/everything_atd.cpp b/atdcpp/test/cpp-expected/everything_atd.cpp index f07f412a..72722a93 100644 --- a/atdcpp/test/cpp-expected/everything_atd.cpp +++ b/atdcpp/test/cpp-expected/everything_atd.cpp @@ -113,6 +113,15 @@ template return val.GetString(); } +[[maybe_unused]] std::string _atd_read_abstract(const rapidjson::Value &val) +{ + // will convert val to string + rapidjson::StringBuffer buffer; + rapidjson::Writer writer(buffer); + val.Accept(writer); + return buffer.GetString(); +} + template [[maybe_unused]] auto _atd_read_array(F read_func, const rapidjson::Value &val) { @@ -265,6 +274,12 @@ template writer.String(value.c_str()); } +[[maybe_unused]] void _atd_write_abstract(const std::string &value, rapidjson::Writer& writer) +{ + // writes string value as raw json + writer.RawValue(value.c_str(), value.size(), rapidjson::kStringType); +} + template [[maybe_unused]] void _atd_write_array(F write_func, const V& values, rapidjson::Writer& writer) { @@ -952,6 +967,9 @@ Root Root::from_json(const rapidjson::Value & doc) { if (doc.HasMember("options")) record.options = _atd_read_array([](const auto &v){return _atd_read_option([](const auto &v){return _atd_read_int(v);}, v);}, doc["options"]); else record.options = _atd_missing_json_field("Root", "options"); + if (doc.HasMember("untyped_things")) + record.untyped_things = _atd_read_array([](const auto &v){return _atd_read_abstract(v);}, doc["untyped_things"]); + else record.untyped_things = _atd_missing_json_field("Root", "untyped_things"); if (doc.HasMember("parametrized_record")) record.parametrized_record = IntFloatParametrizedRecord::from_json(doc["parametrized_record"]); else record.parametrized_record = _atd_missing_json_field("Root", "parametrized_record"); @@ -1040,6 +1058,8 @@ void Root::to_json(const Root &t, rapidjson::Writer &wr _atd_write_array([](auto v, auto &w){_atd_write_nullable([](auto v, auto &w){_atd_write_int(v, w);}, v, w);}, t.nullables, writer); writer.Key("options"); _atd_write_array([](auto v, auto &w){_atd_write_option([](auto v, auto &w){_atd_write_int(v, w);}, v, w);}, t.options, writer); + writer.Key("untyped_things"); + _atd_write_array([](auto v, auto &w){_atd_write_abstract(v, w);}, t.untyped_things, writer); writer.Key("parametrized_record"); IntFloatParametrizedRecord::to_json(t.parametrized_record, writer); writer.Key("parametrized_tuple"); diff --git a/atdcpp/test/cpp-expected/everything_atd.hpp b/atdcpp/test/cpp-expected/everything_atd.hpp index ecca746e..3d0862a5 100644 --- a/atdcpp/test/cpp-expected/everything_atd.hpp +++ b/atdcpp/test/cpp-expected/everything_atd.hpp @@ -284,6 +284,7 @@ struct Root { std::map assoc4; std::vector> nullables; std::vector> options; + std::vector untyped_things; typedefs::IntFloatParametrizedRecord parametrized_record; typedefs::KindParametrizedTuple parametrized_tuple; uint16_t wrapped;