TEST(Serialization, EnvironmentObject) { ASSERT_GT(output_serializers<EnvironmentObject>::value, 0);
std::stringstream ss;
{ cereal::PortableBinaryOutputArchive oarchive(ss);
std::shared_ptr<EnvironmentObject> ptr = std::make_shared<RoadLane>();
ptr->name("my lane"); //ptr->type(RoadLaneType::MIDDLE);
oarchive(ptr);
}
{ cereal::PortableBinaryInputArchive iarchive(ss);
std::shared_ptr<EnvironmentObject> obj;
iarchive(obj);
RoadLane *lane = dynamic_cast<RoadLane*>(obj.get());
ASSERT_NE(nullptr, lane);
ASSERT_EQ(std::string("my lane"), lane->name()); }
}
The test executable gets compiled with CMake:
add_executable(street_environment_test ${TESTS})target_link_libraries(street_environment_test PRIVATE street_environment gtest gtest_main)
The code compiles but it fails during runtime with:
C++ exception with description "Trying to save an unregistered polymorphic type (street_environment::RoadLane).
Make sure your type is registered with CEREAL_REGISTER_TYPE and that the archive you are using was included (and registered with CEREAL_REGISTER_ARCHIVE) prior to calling CEREAL_REGISTER_TYPE.
If your type is already registered and you still see this error, you may need to use CEREAL_REGISTER_DYNAMIC_INIT." thrown in the test body.
As you see, I'm already using CEREAL_REGISTER_TYPE and CEREAL_REGISTER_DYNAMIC_INIT but it is still not working.
Thanks for your help.