mapping::type::Any: Fix retrieve of null any.

This commit is contained in:
Leonid Stryzhevskyi 2023-01-29 04:55:51 +02:00
parent 594ec76c7f
commit cc1888b3e0
2 changed files with 35 additions and 1 deletions

View File

@ -75,7 +75,7 @@ Void Any::retrieve(const Type* type) const {
}
return Void(m_ptr->ptr, type);
}
return nullptr;
return Void(nullptr, type);
}
Any& Any::operator=(std::nullptr_t) {

View File

@ -538,6 +538,40 @@ void ObjectTest::onRun() {
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "Test 18...");
oatpp::parser::json::mapping::ObjectMapper mapper;
auto dto = PolymorphicDto3::createShared();
dto->type = "str";
dto->polymorph = nullptr;
OATPP_ASSERT(dto->polymorph.getValueType() == oatpp::Any::Class::getType())
auto json = mapper.writeToString(dto);
OATPP_LOGD(TAG, "json0='%s'", json->c_str())
auto dtoClone = mapper.readFromString<oatpp::Object<PolymorphicDto3>>(json);
auto jsonClone = mapper.writeToString(dtoClone);
OATPP_LOGD(TAG, "json1='%s'", jsonClone->c_str())
OATPP_ASSERT(json == jsonClone)
OATPP_ASSERT(dtoClone->polymorph == nullptr)
OATPP_ASSERT(dtoClone->polymorph.getValueType() == oatpp::Any::Class::getType())
OATPP_ASSERT(dtoClone->polymorph.getStoredType() == oatpp::String::Class::getType())
auto polymorphClone = dtoClone->polymorph.retrieve<oatpp::String>();
OATPP_ASSERT(polymorphClone == nullptr)
OATPP_ASSERT(polymorphClone.getValueType() == oatpp::String::Class::getType())
OATPP_LOGI(TAG, "OK");
}
}
}}}}}}