Skip to content

Customizing behaviour on incorrect type in JSON #21

Description

@omartijn

I'd like to be able to customize what happens when deserializing a value that is defined in the JSON, but that has the wrong type. As an example, the following JSON:

{"x":"abc"}

and deserializing like this:

struct X {
    int x;

    template <typename io_type>
    void json_io(io_type& io)
    {
        json_dto::optional("x", x, 0);
    }
};

This leads to an exception because we are expecting a number, but are getting a string instead. It'd be nice if we could set a policy that we use the default value in that case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions