lganzzzo on master
Add hints and advice to the thr… Merge pull request #396 from ba… (compare)
bamkrs on master
Fix #324 (#395) * Attempt to p… (compare)
Hello @madkote ,
I don't have any direct recommendations, but there are some points to consider:
Simple API
- then it should be very easy to use any Redis client, and the process of integration should be straight forward.Async API
- then things become more complicated because, in oatpp-coroutines, you have to user oatpp-coroutines based API. It also depends on what kind of Redis API you are planning to use...Something like that...
Please let me know if you have more questions.
DTO_FIELD(Int64, time);
};
class ResponseDto : public oatpp::data::mapping::type::Object
{
DTO_INIT(ResponseDto, Object)
DTO_FIELD(HeaderDto::ObjectWrapper, header);
};
#include "oatpp/parser/json/mapping/ObjectMapper.hpp"
#include "oatpp/core/macro/codegen.hpp"
#include <iostream>
#include OATPP_CODEGEN_BEGIN(DTO)
class MyBaseDto : public oatpp::data::mapping::type::Object {
DTO_INIT(MyBaseDto, Object)
DTO_FIELD(String, myBaseDtoField);
};
class HeaderDto : public MyBaseDto /* Should also extend a class here */ {
DTO_INIT(HeaderDto, MyBaseDto)
DTO_FIELD(Int64, time);
};
class ResponseDto : public oatpp::data::mapping::type::Object {
DTO_INIT(ResponseDto, Object)
DTO_FIELD(HeaderDto::ObjectWrapper, header) = HeaderDto::createShared(); // Don't forger to initialize object
};
#include OATPP_CODEGEN_END(DTO)
void run() {
auto dto = ResponseDto::createShared();
dto->header->time = 0;
dto->header->myBaseDtoField = "Hello base class";
auto objectMapper = oatpp::parser::json::mapping::ObjectMapper::createShared();
auto json = objectMapper->writeToString(dto);
std::cout << json->c_str() << std::endl;
}
int main() {
oatpp::base::Environment::init();
run();
oatpp::base::Environment::destroy();
return 0;
}
Hello, i have a problem/question with your DTO component of oat++. I try to generate an packet with different types of objects but I can't assign inherited classes. I show you my problem with a little example
...
class Param : public oatpp::data::mapping::type::Object
{
DTO_INIT(Param , Object)
};
class RealParam : public Param
{
DTO_INIT(RealParam, Param)
DTO_FIELD(Int32, magic);
};
class Packet : public oatpp::data::mapping::type::Object
{
DTO_INIT(Packet, Object)
DTO_FIELD(List<Param::ObjectWrapper>::ObjectWrapper, params)
= List<Param::ObjectWrapper>::createShared();
};
...
When I try to add an instance (ObjectWrapper) of type RealParam to the list of Packet, I only get an error message from the compiler that there is no known conversion from RealParam::ObjectWrapper to Param::ObjectWrapper. Is there a way to explicitly cast the object or am I still making a mistake somewhere?
Hello @DF-Dave ,
It is possible to cast ObjectWrapper
using oatpp::data::mapping::type::static_wrapper_cast
, and it will compile:
class Param : public oatpp::data::mapping::type::Object {
DTO_INIT(Param , Object);
};
class RealParam : public Param {
DTO_INIT(RealParam, Param)
DTO_FIELD(Int32, magic);
};
class Packet : public oatpp::data::mapping::type::Object {
DTO_INIT(Packet, Object)
DTO_FIELD(List<Param::ObjectWrapper>::ObjectWrapper, params) = List<Param::ObjectWrapper>::createShared();
};
...
auto packet = Packet::createShared();
auto realParam = RealParam::createShared();
realParam->magic = 10;
Param::ObjectWrapper param = oatpp::data::mapping::type::static_wrapper_cast<Param>(realParam);
packet->params->pushBack(param);
But the output will miss the magic
int32 number:
{
"params": [
{}
]
}