Stiffstream / json_dto

A small header-only library for converting data between json representation and c++ structs
BSD 3-Clause "New" or "Revised" License
149 stars 18 forks source link

nullable_t fails for containers with null values #20

Closed omartijn closed 10 months ago

omartijn commented 10 months ago
#include <json_dto/pub.hpp>
#include <string>
#include <vector>

struct nullable {
    std::vector<json_dto::nullable_t<std::string>> strings;

    template <typename io_type>
    void json_io(io_type& io) {
        io& json_dto::optional_no_default("strings", strings);
    }
};

int main() {
    std::string serialized1{R"({"strings":[null]})"};
    json_dto::from_json<nullable>(serialized1);
}

Unless I'm mistaken, this should work. The values inside the vector are nullable, so it should be allowed to deserialize a JSON null. It fails with an exception, though.

eao197 commented 10 months ago

Hi! Thanks for reporting. I'll take a look at it.

eao197 commented 10 months ago

Could you check the latest commit from issue-20-v1 branch? I hope it fixes the problem.

omartijn commented 10 months ago

Yes! I can confirm that the problem is fixed on that branch. :+1:

eao197 commented 10 months ago

Great!

eao197 commented 10 months ago

I've fixed v.0.3.2 with the resolution of this issue.

omartijn commented 10 months ago

Perfect! Thank you.