c++dtooat++

oat++ : put DTO in a list of DTOs


I'm trying to create a single big DTO from multiple DTOs, but I am having a lot of trouble to put my DTOs inside a list.

I have two DTOs :

class TypeDocDto : public oatpp::DTO
{
    DTO_INIT(TypeDocDto, DTO)
    DTO_FIELD(Int32, code);
    DTO_FIELD(String, desciption);
};

class DocumentDto : public oatpp::DTO
{
    DTO_INIT(DocumentDto, DTO)
    DTO_FIELD(Int32, docNumber);
    DTO_FIELD(Int32, typeDocNb);
    DTO_FIELD(List<Object<TypeDocDto>>, typeDocs);
};

The idea here is that one document object can carry multiple "TypeDoc" objects.

So I tried to create a list of TypeDocDto, and then to add it to my DocumentDto object.

auto dtoDoc = DocumentDto::createShared();
dtoDoc->docNumber = 0; //That value is whatever for now.
dtoDoc->typeDocNb = 3;

oatpp::List<oatpp::Object<TypeDocDto>> typeDocsList = {};
for (int i = 0; i < dtoDoc->typeDocNb; i++)
{
    auto typedocDto = TypeDocDto::createShared();
    typedocDto->code = i;
    typedocDto->desciption = "foo";
    typeDocsList->emplace(typeDocsList->end(), typedocDto);
}
dtoDoc->typeDocs = typeDocsList;

But I can't manage to put anything in my typeDocsList variable. The object I add seem to be always NULL.

What am I doing wrong ?


Solution

  • Found where the issue comes from.

    It looks like oat++ is a bit finnicky when it comes about declaring the list object.

    //*oatpp::List<oatpp::Object<TypeDocDto>> typeDocsList = {}* should become :
    oatpp::List<oatpp::Object<TypeDocDto>> typeDocsList({});
    

    That precise syntax seems to be required. After that, my code works as intended.