From bae7cf34141ef00bc2bb7d300cf4b7ea390c4ff6 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 24 Dec 2017 01:07:52 +0100 Subject: [PATCH] Prevent generating pull method for non-default constructable classes --- README.md | 6 ++++-- generator/jsonserializationcodegenerator.cpp | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6c8fb19..b1517e9 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,11 @@ The following table shows the mapping of supported C++ types to supported JSON t * For the same reason `const char *` strings are only supported for serialization. * Enums are (de)serialized as their underlying integer value. When deserializing, it is currently *not* checked whether the present integer value is a valid enumeration item. -* For deserialization, iteratables must provide an `emplace_back` method. So deserialization of eg. `std::forward_list` - is currently not supported. * The JSON type for smart pointer depends on the type the pointer refers to. It can also be `null`. +* For deserialization + * iteratables must provide an `emplace_back` method. So deserialization of eg. `std::forward_list` + is currently not supported. + * custom types must provide a default constructor. * For custom (de)serialization, see the section below. ## Usage diff --git a/generator/jsonserializationcodegenerator.cpp b/generator/jsonserializationcodegenerator.cpp index 1362163..0132d4c 100644 --- a/generator/jsonserializationcodegenerator.cpp +++ b/generator/jsonserializationcodegenerator.cpp @@ -205,6 +205,11 @@ void JsonSerializationCodeGenerator::generate(ostream &os) const } os << "}\n"; + // skip printing the pull method for classes without default constructor because deserializing those is currently not supported + if (!relevantClass.record->hasDefaultConstructor()) { + continue; + } + // print pull method os << "template <> " << visibility << " void pull<::" << relevantClass.qualifiedName << ">(::" << relevantClass.qualifiedName << " &reflectable, const ::RAPIDJSON_NAMESPACE::GenericValue<::RAPIDJSON_NAMESPACE::UTF8>::ConstObject &value, "