This patch adds 4 new NLOHMANN_DEFINE_TYPE_<***>_WITH_NAMES macros. They behave the same way as the ones that are there, but require explicit JSON names. Useful for the situation when the fields in the class are following the naming convention that you do not want to expose to JSON, e.g.
class address {
private:
std::string m_street;
int m_housenumber;
int m_postcode;
public:
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_NAMES(address, "street", m_street, "housenumber", m_housenumber, "postcode", m_postcode)
};
or if the name in JSON cannot be used as the field name because it is reserved, e.g.
[x] The source code is amalgamated; that is, after making changes to the sources in the include/nlohmann directory, run make amalgamate to create the single-header files single_include/nlohmann/json.hpp and single_include/nlohmann/json_fwd.hpp. The whole process is described here.
coverage: 100.0%. remained the same when pulling 0c4d8168fd7ce013ba3e074f93c933ccd4b57aa5 on radistmorse:patch-1 into 5d2754306d67d1e654a1a34e1d2e74439a9d53b3 on nlohmann:develop.
This patch adds 4 new
NLOHMANN_DEFINE_TYPE_<***>_WITH_NAMES
macros. They behave the same way as the ones that are there, but require explicit JSON names. Useful for the situation when the fields in the class are following the naming convention that you do not want to expose to JSON, e.g.or if the name in JSON cannot be used as the field name because it is reserved, e.g.
Also, this patch includes the unit tests for the new macros, and the update for the README to describe the new and existing macros better.
Pull request checklist
Read the Contribution Guidelines for detailed information.
include/nlohmann
directory, runmake amalgamate
to create the single-header filessingle_include/nlohmann/json.hpp
andsingle_include/nlohmann/json_fwd.hpp
. The whole process is described here.