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

Force case for some fields regardless of processors #115

Closed LordTermor closed 1 month ago

LordTermor commented 1 month ago

Is it possible to force snake_case for some fields even when rfl::SnakeCaseToCamelCase is used?

Having something like this:

struct Structure {
  rfl::Rename<"snake_case_field", std::string> snake_case_field;
};

...

auto result = rfl::json::write<rfl::SnakeCaseToCamelCase>(structure_value);

still makes field's name to be camel case.

liuzicheng1987 commented 1 month ago

@LordTermor , I have actually been thinking about this a couple of days ago. I agree that the way I would expect this to behave is for rfl::Rename to override the processor instead of the other way around. But currently that is not the way it behaves. I think I can change that, though.

liuzicheng1987 commented 1 month ago

@LordTermor , if you now check out the main branch, it will behave as expected, with Rename overriding the processor. I will do a release over the weekend which will include this as well.