getml / reflect-cpp

A C++20 library for fast serialization, deserialization and validation using reflection. Supports JSON, BSON, CBOR, flexbuffers, msgpack, TOML, XML, YAML / msgpack.org[C++20]
https://getml.github.io/reflect-cpp/
MIT License
783 stars 63 forks source link

How to skip fields? #99

Closed wicast closed 1 month ago

wicast commented 1 month ago

I want to skip fields like: https://serde.rs/attr-skip-serializing.html

liuzicheng1987 commented 1 month ago

This is currently unsupported, but it shouldn't be hard to do.

I actually haven't used this feature with serde. I think the syntax could look like this:

struct Person {
     std::string first_name;
     std::string last_name;
     int age;
     rfl::Skip<std::string> town;
};

This would prevent the field from being skipped during serialization and deserialization. We could also include rfl::SkipSerialializing and rfl::SkipDeserializing, just like serde.

liuzicheng1987 commented 1 month ago

@wicast , there is a draft in this branch:

https://github.com/getml/reflect-cpp/tree/f/skip

It's not documented yet, but it basically works as we discussed:

https://github.com/getml/reflect-cpp/blob/f/skip/tests/json/test_skip.cpp

What do you think? Is this what you wanted?

wicast commented 1 month ago

Good enough for me, thank you.