Skip to content

How to custom serialize same data type of vector? #2215

@gzliudan

Description

@gzliudan

for example

struct Item {
    std::vector<int> array1;
    std::vector<int> array2;
};

Item  {
    .array1 = {123};
    .array2 = {123};
};

std::string func1(int i) { return std::string("a") + std::to_string(i + i); } 
std::string func2(int i) { return std::string("b") + std::to_string(i * i); } 

during serialize, I want to apply func1 to each element of array1, apply func2 to each element of array2, so the json will become

{
    "array1": [ "a2", "a4", "a6" ], 
    "array2": [ "b1", "b4", "b9" ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions