oatpp / oatpp-protobuf

Use protobuf messages as regular oatpp DTOs
https://oatpp.io/
Apache License 2.0
5 stars 3 forks source link

I must be missing something ... #4

Open ehallander9591 opened 2 years ago

ehallander9591 commented 2 years ago

My interpretation using this was that I only needed to use the oatpp::protobuf::Object instead of the oatpp::Object template as in

ENDPOINT_INFO(hasPointToPointLOS) { info->summary = "Given two instances of a location and height on a map determine if the two points have a LOS vector between them withing the fidelity of the number_of_steps to examine the LOS vector.";

info->addConsumes<oatpp::protobuf::Object<HasLineOfSightRequest>>("application/json");

info->addResponse<oatpp::protobuf::Object<HasLineOfSightResponse>>(Status::CODE_200, "application/json");

} ENDPOINT("POST", "hasPointToPointLOS", hasPointToPointLOS, BODY_DTO(oatpp::protobuf::Object, requestDto)) { return createDtoResponse(Status::CODE_200, m_terrainService.hasPointToPointLineOfSight(requestDto)); }

however the swagger shows

"Unknown Type: oatpp::protobuf::AbstractObject"

as my payload json, and if push through and type in a valid json object for my request object, say such as

{ "locationFrom": { "latitude": 0.0, "longitude": 0.0 }, "locationTo": { "latitude": 0.0, "longitude": 0.0 }, "numberOfSteps": 10 }

That leads to deserialization error

{ "status": "ERROR", "code": 500, "message": "[oatpp::parser::json::mapping::Deserializer::deserialize()]: Error. No deserialize method for type 'oatpp::protobuf::AbstractObject'" }

So, I must be missing something, and am ready to move onto a different C++ Rest framework.

There is some plumbing concerning getting the oatpp::protobuf::Object to get all that toInterpretation fromInterpretation working, but I don't see it yet.

FYI, I have this built against 1.2.5 oatpp on Windows 10 using VS 2017 Pro.

darkpursuer commented 1 year ago

After some investigation, you need to specify the protobuf when creating the object_mapper:

auto serializer_config =
      oatpp::parser::json::mapping::Serializer::Config::createShared();
serializer_config->enabledInterpretations.push_back("protobuf");
auto deserializer_config =
    oatpp::parser::json::mapping::Deserializer::Config::createShared();
deserializer_config->enabledInterpretations.push_back("protobuf");
auto objectMapper = oatpp::parser::json::mapping::ObjectMapper::createShared(
    serializer_config, deserializer_config);