diff --git a/parser/json/mapping/Serializer.cpp b/parser/json/mapping/Serializer.cpp index 5c3a2974..8e11b7c4 100644 --- a/parser/json/mapping/Serializer.cpp +++ b/parser/json/mapping/Serializer.cpp @@ -22,415 +22,76 @@ * ***************************************************************************/ -#include "./Serializer.hpp" +#include "Serializer.hpp" #include "oatpp/parser/json/Utils.hpp" namespace oatpp { namespace parser { namespace json { namespace mapping { -void Serializer::writeStringValue(oatpp::data::stream::OutputStream* stream, p_char8 data, v_int32 size) { +void Serializer::writeString(oatpp::data::stream::OutputStream* stream, p_char8 data, v_int32 size) { auto encodedValue = Utils::escapeString(data, size, false); stream->writeChar('\"'); stream->write(encodedValue); stream->writeChar('\"'); } - -void Serializer::writeStringValue(oatpp::data::stream::OutputStream* stream, const char* data) { - writeStringValue(stream, (p_char8)data, (v_int32)std::strlen(data)); + +void Serializer::writeString(oatpp::data::stream::OutputStream* stream, const char* data) { + writeString(stream, (p_char8)data, (v_int32)std::strlen(data)); } -void Serializer::writeString(oatpp::data::stream::OutputStream* stream, - void* object, - Property* field, - const std::shared_ptr& config) { - auto value = oatpp::data::mapping::type::static_wrapper_cast(field->get(object)); - if(value) { - writeStringValue(stream, field->name); - stream->write(": ", 2); - writeStringValue(stream, value->getData(), value->getSize()); - } else if(config->includeNullFields) { - writeStringValue(stream, field->name); - stream->write(": null", 6); - } -} - -void Serializer::writeObject(oatpp::data::stream::OutputStream* stream, - void* object, - Property* field, - const std::shared_ptr& config){ - auto value = oatpp::data::mapping::type::static_wrapper_cast(field->get(object)); - if(value) { - writeStringValue(stream, field->name); - stream->write(": ", 2); - writeObject(stream, field->type, value.get(), config); - } else if(config->includeNullFields) { - writeStringValue(stream, field->name); - stream->write(": null", 6); - } -} - -void Serializer::writeListOfString(oatpp::data::stream::OutputStream* stream, - AbstractList* list, - const std::shared_ptr& config){ +void Serializer::writeList(oatpp::data::stream::OutputStream* stream, const AbstractList::ObjectWrapper& list, const std::shared_ptr& config) { stream->writeChar('['); bool first = true; auto curr = list->getFirstNode(); + while(curr != nullptr){ - - auto value = oatpp::data::mapping::type::static_wrapper_cast(curr->getData()); - if(value) { + auto value = curr->getData(); + if(value || config->includeNullFields) { (first) ? first = false : stream->write(", ", 2); - writeStringValue(stream, value->getData(), value->getSize()); - } else if(config->includeNullFields) { - (first) ? first = false : stream->write(", ", 2); - stream->write("null", 4); + writeValue(stream, curr->getData(), config); } - curr = curr->getNext(); - } stream->writeChar(']'); - } -void Serializer::writeListOfObject(oatpp::data::stream::OutputStream* stream, - AbstractList* list, - const Type* const type, - const std::shared_ptr& config){ - stream->writeChar('['); - bool first = true; - auto curr = list->getFirstNode(); - while(curr != nullptr){ - - auto value = oatpp::data::mapping::type::static_wrapper_cast(curr->getData()); - if(value) { - (first) ? first = false : stream->write(", ", 2); - writeObject(stream, type, value.get(), config); - } else if(config->includeNullFields) { - (first) ? first = false : stream->write(", ", 2); - stream->write("null", 4); - } - - curr = curr->getNext(); - - } - - stream->writeChar(']'); - -} - -void Serializer::writeListOfList(oatpp::data::stream::OutputStream* stream, - AbstractList* list, - const Type* const type, - const std::shared_ptr& config){ - stream->writeChar('['); - bool first = true; - auto curr = list->getFirstNode(); - while(curr != nullptr){ - - auto value = oatpp::data::mapping::type::static_wrapper_cast(curr->getData()); - if(value) { - (first) ? first = false : stream->write(", ", 2); - writeListCollection(stream, value.get(), type, config); - } else if(config->includeNullFields) { - (first) ? first = false : stream->write(", ", 2); - stream->write("null", 4); - } - - curr = curr->getNext(); - - } - - stream->writeChar(']'); - -} - -void Serializer::writeListOfListMap(oatpp::data::stream::OutputStream* stream, - AbstractList* list, - const Type* const type, - const std::shared_ptr& config){ - stream->writeChar('['); - bool first = true; - auto curr = list->getFirstNode(); - while(curr != nullptr){ - - auto value = oatpp::data::mapping::type::static_wrapper_cast(curr->getData()); - if(value) { - (first) ? first = false : stream->write(", ", 2); - writeListMapCollection(stream, value.get(), type, config); - } else if(config->includeNullFields) { - (first) ? first = false : stream->write(", ", 2); - stream->write("null", 4); - } - - curr = curr->getNext(); - - } - - stream->writeChar(']'); - -} - -void Serializer::writeListCollection(oatpp::data::stream::OutputStream* stream, - AbstractList* list, - const Type* const type, - const std::shared_ptr& config){ - - Type* itemType = *(type->params.begin()); - auto itemTypeName = itemType->name; - - if(itemTypeName == oatpp::data::mapping::type::__class::String::CLASS_NAME){ - writeListOfString(stream, list, config); - } else if(itemTypeName == oatpp::data::mapping::type::__class::Int32::CLASS_NAME) { - writeListOfSimpleData(stream, list, config); - } else if(itemTypeName == oatpp::data::mapping::type::__class::Int64::CLASS_NAME) { - writeListOfSimpleData(stream, list, config); - } else if(itemTypeName == oatpp::data::mapping::type::__class::Float32::CLASS_NAME) { - writeListOfSimpleData(stream, list, config); - } else if(itemTypeName == oatpp::data::mapping::type::__class::Float64::CLASS_NAME) { - writeListOfSimpleData(stream, list, config); - } else if(itemTypeName == oatpp::data::mapping::type::__class::Boolean::CLASS_NAME) { - writeListOfSimpleData(stream, list, config); - } else if(itemTypeName == oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME) { - writeListOfObject(stream, list, itemType, config); - } else if(itemTypeName == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME) { - writeListOfList(stream, list, itemType, config); - } else if(itemTypeName == oatpp::data::mapping::type::__class::AbstractListMap::CLASS_NAME) { - writeListOfListMap(stream, list, itemType, config); - } - -} - -void Serializer::writeList(oatpp::data::stream::OutputStream* stream, - void* object, - Property* field, - const std::shared_ptr& config){ - auto value = oatpp::data::mapping::type::static_wrapper_cast(field->get(object)); - if(value) { - writeStringValue(stream, field->name); - stream->write(": ", 2); - writeListCollection(stream, value.get(), field->type, config); - } else if(config->includeNullFields) { - writeStringValue(stream, field->name); - stream->write(": null", 6); - } -} - -void Serializer::writeListMapOfString(oatpp::data::stream::OutputStream* stream, - AbstractListMap* map, - const std::shared_ptr& config) { - +void Serializer::writeFieldsMap(oatpp::data::stream::OutputStream* stream, const AbstractFieldsMap::ObjectWrapper& map, const std::shared_ptr& config) { stream->writeChar('{'); bool first = true; auto curr = map->getFirstEntry(); + while(curr != nullptr){ - - auto value = oatpp::data::mapping::type::static_wrapper_cast(curr->getValue()); - if(value) { + auto value = curr->getValue(); + if(value || config->includeNullFields) { (first) ? first = false : stream->write(", ", 2); - auto key = oatpp::data::mapping::type::static_wrapper_cast(curr->getKey()); - writeStringValue(stream, key->getData(), key->getSize()); + auto key = curr->getKey(); + writeString(stream, key->getData(), key->getSize()); stream->write(": ", 2); - writeStringValue(stream, value->getData(), value->getSize()); - } else if(config->includeNullFields) { - (first) ? first = false : stream->write(", ", 2); - auto key = oatpp::data::mapping::type::static_wrapper_cast(curr->getKey()); - writeStringValue(stream, key->getData(), key->getSize()); - stream->write(": null", 6); + writeValue(stream, curr->getValue(), config); } - curr = curr->getNext(); - } stream->writeChar('}'); - -} - -void Serializer::writeListMapOfObject(oatpp::data::stream::OutputStream* stream, - AbstractListMap* map, - const Type* const type, - const std::shared_ptr& config){ - stream->writeChar('{'); - bool first = true; - auto curr = map->getFirstEntry(); - while(curr != nullptr){ - - auto value = oatpp::data::mapping::type::static_wrapper_cast(curr->getValue()); - if(value) { - (first) ? first = false : stream->write(", ", 2); - auto key = oatpp::data::mapping::type::static_wrapper_cast(curr->getKey()); - writeStringValue(stream, key->getData(), key->getSize()); - stream->write(": ", 2); - writeObject(stream, type, value.get(), config); - } else if(config->includeNullFields) { - (first) ? first = false : stream->write(", ", 2); - auto key = oatpp::data::mapping::type::static_wrapper_cast(curr->getKey()); - writeStringValue(stream, key->getData(), key->getSize()); - stream->write(": null", 6); - } - - curr = curr->getNext(); - - } - - stream->writeChar('}'); - } -void Serializer::writeListMapOfList(oatpp::data::stream::OutputStream* stream, - AbstractListMap* map, - const Type* const type, - const std::shared_ptr& config){ - stream->writeChar('{'); - bool first = true; - auto curr = map->getFirstEntry(); - while(curr != nullptr){ - - auto value = oatpp::data::mapping::type::static_wrapper_cast(curr->getValue()); - if(value) { - (first) ? first = false : stream->write(", ", 2); - auto key = oatpp::data::mapping::type::static_wrapper_cast(curr->getKey()); - writeStringValue(stream, key->getData(), key->getSize()); - stream->write(": ", 2); - writeListCollection(stream, value.get(), type, config); - } else if(config->includeNullFields) { - (first) ? first = false : stream->write(", ", 2); - auto key = oatpp::data::mapping::type::static_wrapper_cast(curr->getKey()); - writeStringValue(stream, key->getData(), key->getSize()); - stream->write(": null", 6); - } - - curr = curr->getNext(); - - } - - stream->writeChar('}'); - -} - -void Serializer::writeListMapOfListMap(oatpp::data::stream::OutputStream* stream, - AbstractListMap* map, - const Type* const type, - const std::shared_ptr& config){ - stream->writeChar('{'); - bool first = true; - auto curr = map->getFirstEntry(); - while(curr != nullptr){ - - auto value = oatpp::data::mapping::type::static_wrapper_cast(curr->getValue()); - if(value) { - (first) ? first = false : stream->write(", ", 2); - auto key = oatpp::data::mapping::type::static_wrapper_cast(curr->getKey()); - writeStringValue(stream, key->getData(), key->getSize()); - stream->write(": ", 2); - writeListMapCollection(stream, value.get(), type, config); - } else if(config->includeNullFields) { - (first) ? first = false : stream->write(", ", 2); - auto key = oatpp::data::mapping::type::static_wrapper_cast(curr->getKey()); - writeStringValue(stream, key->getData(), key->getSize()); - stream->write(": null", 6); - } - - curr = curr->getNext(); - - } - - stream->writeChar('}'); - -} - -void Serializer::writeListMapCollection(oatpp::data::stream::OutputStream* stream, - AbstractListMap* map, - const Type* const type, - const std::shared_ptr& config){ - auto it = type->params.begin(); - Type* keyType = *it ++; - auto keyTypeName = keyType->name; - - Type* valueType = *it; - auto valueTypeName = valueType->name; - - if(keyTypeName != oatpp::data::mapping::type::__class::String::CLASS_NAME){ - throw std::runtime_error("[oatpp::parser::json::mapping::Serializer::writeListMapCollection()]: Invalid json map key. Key should be String"); - } - - if(valueTypeName == oatpp::data::mapping::type::__class::String::CLASS_NAME){ - writeListMapOfString(stream, map, config); - } else if(valueTypeName == oatpp::data::mapping::type::__class::Int32::CLASS_NAME) { - writeListMapOfSimpleData(stream, map, config); - } else if(valueTypeName == oatpp::data::mapping::type::__class::Int64::CLASS_NAME) { - writeListMapOfSimpleData(stream, map, config); - } else if(valueTypeName == oatpp::data::mapping::type::__class::Float32::CLASS_NAME) { - writeListMapOfSimpleData(stream, map, config); - } else if(valueTypeName == oatpp::data::mapping::type::__class::Float64::CLASS_NAME) { - writeListMapOfSimpleData(stream, map, config); - } else if(valueTypeName == oatpp::data::mapping::type::__class::Boolean::CLASS_NAME) { - writeListMapOfSimpleData(stream, map, config); - } else if(valueTypeName == oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME) { - writeListMapOfObject(stream, map, valueType, config); - } else if(valueTypeName == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME) { - writeListMapOfList(stream, map, valueType, config); - } else if(valueTypeName == oatpp::data::mapping::type::__class::AbstractListMap::CLASS_NAME) { - writeListMapOfListMap(stream, map, valueType, config); - } - -} - -void Serializer::writeListMap(oatpp::data::stream::OutputStream* stream, - void* object, - Property* field, - const std::shared_ptr& config){ - auto value = oatpp::data::mapping::type::static_wrapper_cast(field->get(object)); - if(value) { - writeStringValue(stream, field->name); - stream->write(": ", 2); - writeListMapCollection(stream, value.get(), field->type, config); - } else if(config->includeNullFields) { - writeStringValue(stream, field->name); - stream->write(": null", 6); - } -} - -void Serializer::writeObject(oatpp::data::stream::OutputStream* stream, - const Type* type, - Object* object, - const std::shared_ptr& config){ +void Serializer::writeObject(oatpp::data::stream::OutputStream* stream, const PolymorphicWrapper& polymorph, const std::shared_ptr& config) { stream->writeChar('{'); + bool first = true; - auto fields = type->properties->getList(); + auto fields = polymorph.valueType->properties->getList(); + Object* object = polymorph.get(); + for (auto const& field : fields) { - auto abstractValue = field->get(object); - if(abstractValue) { + auto value = field->get(object); + if(value || config->includeNullFields) { (first) ? first = false : stream->write(", ", 2); - } else if(config->includeNullFields) { - (first) ? first = false : stream->write(", ", 2); - } - - auto type = field->type; - auto typeName = type->name; - - if(typeName == oatpp::data::mapping::type::__class::String::CLASS_NAME){ - writeString(stream, object, field, config); - } else if(typeName == oatpp::data::mapping::type::__class::Int32::CLASS_NAME) { - writeSimpleData(stream, object, field, config); - } else if(typeName == oatpp::data::mapping::type::__class::Int64::CLASS_NAME) { - writeSimpleData(stream, object, field, config); - } else if(typeName == oatpp::data::mapping::type::__class::Float32::CLASS_NAME) { - writeSimpleData(stream, object, field, config); - } else if(typeName == oatpp::data::mapping::type::__class::Float64::CLASS_NAME) { - writeSimpleData(stream, object, field, config); - } else if(typeName == oatpp::data::mapping::type::__class::Boolean::CLASS_NAME) { - writeSimpleData(stream, object, field, config); - } else if(typeName == oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME) { - writeObject(stream, object, field, config); - } else if(typeName == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME) { - writeList(stream, object, field, config); - } else if(typeName == oatpp::data::mapping::type::__class::AbstractListMap::CLASS_NAME) { - writeListMap(stream, object, field, config); + writeString(stream, field->name); + stream->write(": ", 2); + writeValue(stream, value, config); } } @@ -439,4 +100,42 @@ void Serializer::writeObject(oatpp::data::stream::OutputStream* stream, } +void Serializer::writeValue(oatpp::data::stream::OutputStream* stream, const AbstractObjectWrapper& polymorph, const std::shared_ptr& config) { + + const char* typeName = polymorph.valueType->name; + + if(typeName == oatpp::data::mapping::type::__class::String::CLASS_NAME) { + auto str = oatpp::data::mapping::type::static_wrapper_cast(polymorph); + writeString(stream, str->getData(), str->getSize()); + } else if(typeName == oatpp::data::mapping::type::__class::Int8::CLASS_NAME) { + writeSimpleData(stream, oatpp::data::mapping::type::static_wrapper_cast(polymorph)); + } else if(typeName == oatpp::data::mapping::type::__class::Int16::CLASS_NAME) { + writeSimpleData(stream, oatpp::data::mapping::type::static_wrapper_cast(polymorph)); + } else if(typeName == oatpp::data::mapping::type::__class::Int32::CLASS_NAME) { + writeSimpleData(stream, oatpp::data::mapping::type::static_wrapper_cast(polymorph)); + } else if(typeName == oatpp::data::mapping::type::__class::Int64::CLASS_NAME) { + writeSimpleData(stream, oatpp::data::mapping::type::static_wrapper_cast(polymorph)); + } else if(typeName == oatpp::data::mapping::type::__class::Float32::CLASS_NAME) { + writeSimpleData(stream, oatpp::data::mapping::type::static_wrapper_cast(polymorph)); + } else if(typeName == oatpp::data::mapping::type::__class::Float64::CLASS_NAME) { + writeSimpleData(stream, oatpp::data::mapping::type::static_wrapper_cast(polymorph)); + } else if(typeName == oatpp::data::mapping::type::__class::Boolean::CLASS_NAME) { + writeSimpleData(stream, oatpp::data::mapping::type::static_wrapper_cast(polymorph)); + } else if(typeName == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME) { + writeList(stream, oatpp::data::mapping::type::static_wrapper_cast(polymorph), config); + } else if(typeName == oatpp::data::mapping::type::__class::AbstractListMap::CLASS_NAME) { + // TODO Assert that key is String + writeFieldsMap(stream, oatpp::data::mapping::type::static_wrapper_cast(polymorph), config); + } else if(typeName == oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME) { + writeObject(stream, oatpp::data::mapping::type::static_wrapper_cast(polymorph), config); + } else { + if(config->throwOnUnknownTypes) { + throw std::runtime_error("[oatpp::kafka::protocol::mapping::Serializer::writeField]: Unknown data type"); + } else { + writeString(stream, ""); + } + } + +} + }}}} diff --git a/parser/json/mapping/Serializer.hpp b/parser/json/mapping/Serializer.hpp index c86da147..63f11d5e 100644 --- a/parser/json/mapping/Serializer.hpp +++ b/parser/json/mapping/Serializer.hpp @@ -48,14 +48,13 @@ public: typedef oatpp::data::mapping::type::Object Object; typedef oatpp::String String; - typedef oatpp::data::mapping::type::List< - oatpp::data::mapping::type::AbstractObjectWrapper - > AbstractList; + template + using PolymorphicWrapper = data::mapping::type::PolymorphicWrapper; + + typedef oatpp::data::mapping::type::AbstractObjectWrapper AbstractObjectWrapper; + typedef oatpp::data::mapping::type::List AbstractList; + typedef oatpp::data::mapping::type::ListMap AbstractFieldsMap; - typedef oatpp::data::mapping::type::ListMap< - oatpp::data::mapping::type::AbstractObjectWrapper, - oatpp::data::mapping::type::AbstractObjectWrapper - > AbstractListMap; public: class Config : public oatpp::base::Controllable { @@ -69,172 +68,42 @@ public: } bool includeNullFields = true; + bool throwOnUnknownTypes = true; }; private: - static void writeStringValue(oatpp::data::stream::OutputStream* stream, p_char8 data, v_int32 size); - static void writeStringValue(oatpp::data::stream::OutputStream* stream, const char* data); - - static void writeString(oatpp::data::stream::OutputStream* stream, - void* object, - Property* field, - const std::shared_ptr& config); + static void writeString(oatpp::data::stream::OutputStream* stream, p_char8 data, v_int32 size); + static void writeString(oatpp::data::stream::OutputStream* stream, const char* data); template - static void writeSimpleData(oatpp::data::stream::OutputStream* stream, - void* object, - Property* field, - const std::shared_ptr& config){ - auto value = oatpp::data::mapping::type::static_wrapper_cast(field->get(object)); - if(value) { - writeStringValue(stream, field->name); - stream->write(": ", 2); + static void writeSimpleData(oatpp::data::stream::OutputStream* stream, const PolymorphicWrapper& value){ + if(value){ stream->writeAsString(value.get()->getValue()); - } else if(config->includeNullFields) { - writeStringValue(stream, field->name); - stream->write(": null", 6); + } else { + stream->write("null", 4); } } - static void writeObject(oatpp::data::stream::OutputStream* stream, - void* object, - Property* field, - const std::shared_ptr& config); + static void writeList(oatpp::data::stream::OutputStream* stream, const AbstractList::ObjectWrapper& list, const std::shared_ptr& config); + static void writeFieldsMap(oatpp::data::stream::OutputStream* stream, const AbstractFieldsMap::ObjectWrapper& map, const std::shared_ptr& config); + static void writeObject(oatpp::data::stream::OutputStream* stream, const PolymorphicWrapper& polymorph, const std::shared_ptr& config); - static void writeListOfString(oatpp::data::stream::OutputStream* stream, - AbstractList* list, - const std::shared_ptr& config); - - template - static void writeListOfSimpleData(oatpp::data::stream::OutputStream* stream, - AbstractList* list, - const std::shared_ptr& config){ - stream->writeChar('['); - bool first = true; - auto curr = list->getFirstNode(); - while(curr != nullptr){ - - auto value = oatpp::data::mapping::type::static_wrapper_cast(curr->getData()); - if(value) { - (first) ? first = false : stream->write(", ", 2); - stream->writeAsString(value.get()->getValue()); - } else if(config->includeNullFields) { - (first) ? first = false : stream->write(", ", 2); - stream->write("null", 4); - } - - curr = curr->getNext(); - - } - - stream->writeChar(']'); - - } - - static void writeListOfObject(oatpp::data::stream::OutputStream* stream, - AbstractList* list, - const Type* const type, - const std::shared_ptr& config); - - static void writeListOfList(oatpp::data::stream::OutputStream* stream, - AbstractList* list, - const Type* const type, - const std::shared_ptr& config); - - static void writeListOfListMap(oatpp::data::stream::OutputStream* stream, - AbstractList* list, - const Type* const type, - const std::shared_ptr& config); - - static void writeListCollection(oatpp::data::stream::OutputStream* stream, - AbstractList* list, - const Type* const type, - const std::shared_ptr& config); - - static void writeList(oatpp::data::stream::OutputStream* stream, - void* object, - Property* field, - const std::shared_ptr& config); - - static void writeListMapOfString(oatpp::data::stream::OutputStream* stream, - AbstractListMap* map, - const std::shared_ptr& config); - - template - static void writeListMapOfSimpleData(oatpp::data::stream::OutputStream* stream, - AbstractListMap* map, - const std::shared_ptr& config){ - stream->writeChar('{'); - bool first = true; - auto curr = map->getFirstEntry(); - while(curr != nullptr){ - - auto value = oatpp::data::mapping::type::static_wrapper_cast(curr->getValue()); - if(value) { - (first) ? first = false : stream->write(", ", 2); - auto key = oatpp::data::mapping::type::static_wrapper_cast(curr->getKey()); - writeStringValue(stream, key->getData(), key->getSize()); - stream->write(": ", 2); - stream->writeAsString(value.get()->getValue()); - } else if(config->includeNullFields) { - (first) ? first = false : stream->write(", ", 2); - auto key = oatpp::data::mapping::type::static_wrapper_cast(curr->getKey()); - writeStringValue(stream, key->getData(), key->getSize()); - stream->write(": null", 6); - } - - curr = curr->getNext(); - - } - - stream->writeChar('}'); - - } - - static void writeListMapOfObject(oatpp::data::stream::OutputStream* stream, - AbstractListMap* map, - const Type* const type, - const std::shared_ptr& config); - - static void writeListMapOfList(oatpp::data::stream::OutputStream* stream, - AbstractListMap* map, - const Type* const type, - const std::shared_ptr& config); - - static void writeListMapOfListMap(oatpp::data::stream::OutputStream* stream, - AbstractListMap* map, - const Type* const type, - const std::shared_ptr& config); - - static void writeListMapCollection(oatpp::data::stream::OutputStream* stream, - AbstractListMap* map, - const Type* const type, - const std::shared_ptr& config); - - static void writeListMap(oatpp::data::stream::OutputStream* stream, - void* object, - Property* field, - const std::shared_ptr& config); - - static void writeObject(oatpp::data::stream::OutputStream* stream, - const Type* const type, - Object* object, - const std::shared_ptr& config); + static void writeValue(oatpp::data::stream::OutputStream* stream, const AbstractObjectWrapper& polymorph, const std::shared_ptr& config); public: static void serialize(const std::shared_ptr& stream, - const oatpp::data::mapping::type::AbstractObjectWrapper& object, + const oatpp::data::mapping::type::AbstractObjectWrapper& polymorph, const std::shared_ptr& config){ - auto type = object.valueType; + auto type = polymorph.valueType; if(type->name == oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME) { - writeObject(stream.get(), type, static_cast(object.get()), config); + writeObject(stream.get(), oatpp::data::mapping::type::static_wrapper_cast(polymorph), config); } else if(type->name == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME) { - writeListCollection(stream.get(), static_cast(object.get()), type, config); + writeList(stream.get(), oatpp::data::mapping::type::static_wrapper_cast(polymorph), config); } else if(type->name == oatpp::data::mapping::type::__class::AbstractListMap::CLASS_NAME) { - writeListMapCollection(stream.get(), static_cast(object.get()), type, config); + writeFieldsMap(stream.get(), oatpp::data::mapping::type::static_wrapper_cast(polymorph), config); } else { throw std::runtime_error("[oatpp::parser::json::mapping::Serializer::serialize()]: Unknown parameter type"); }