nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
41.25k stars 6.57k forks source link

Fix serialisation macros no member variables #4323

Open Yurunsoft opened 3 months ago

Yurunsoft commented 3 months ago

[Describe your pull request here. Please read the text below the line, and make sure you follow the checklist.]

Just like the code in the test, this code will report an error until it is fixed.

The problem is that serialization macros are not supported in classes without member variables.

namespace emptys
{
class empty_intrusive
{
    NLOHMANN_DEFINE_TYPE_INTRUSIVE(empty_intrusive)
};

class empty_intrusive_with_default
{
    NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(empty_intrusive_with_default)
};

class empty_only_serialize
{
    NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(empty_only_serialize)
};

class empty_non_intrusive
{
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(empty_non_intrusive)

class empty_intrusive_non_intrusive_only_serialize
{
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(empty_intrusive_non_intrusive_only_serialize)

class empty_non_intrusive_with_default
{
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(empty_non_intrusive_with_default)

} // namespace emptys

Pull request checklist

Read the Contribution Guidelines for detailed information.

Please don't

coveralls commented 3 months ago

Coverage Status

coverage: 100.0%. remained the same when pulling 5463c2baa87190cde8d78eff2f55675921173b78 on Yurunsoft:fix-macro-no-member into 199dea11b17c533721b26249e2dcaee6ca1d51d3 on nlohmann:develop.