oatpp / oatpp-swagger

OpenApi 3.0.0 docs + Swagger UI for oatpp services
https://oatpp.io/
Apache License 2.0
90 stars 51 forks source link

To use "application/x-www-form-urlencoded" with readBodyDtoAsync #76

Open remioukrat opened 1 year ago

remioukrat commented 1 year ago

If we want to a consume DTO like this info->addConsumes<Object<MyDTO>>("application/x-www-form-urlencoded");

when we try to read DTO like this return request->readBodyToDtoAsync<Object<MyDTO>>(controller->getDefaultObjectMapper()).callbackTo(&MyClass::MyCallback);

There is a problem with the bodyDecoder and the callback is not called.

lganzzzo commented 1 year ago

Hello @remioukrat ,

when we try to read DTO like this return request->readBodyToDtoAsync<Object>(controller->getDefaultObjectMapper()).callbackTo(&MyClass::MyCallback); There is a problem with the bodyDecoder and the callback is not called.

That's because you are trying to make JSON mapper to read application/x-www-form-urlencoded

You have to read body to string first, and then parse that body on your own.

return request->readBodyToString().callbackTo(&MyClass::MyCallback);