mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-08-10 03:16:09 +08:00
feat: Add RequiredForJson JSON
This commit is contained in:
@@ -209,7 +209,8 @@ namespace BlackMisc
|
||||
DisabledForHashing = 1 << 3, //!< Element will be ignored by qHash()
|
||||
DisabledForJson = 1 << 4, //!< Element will be ignored during JSON serialization
|
||||
CaseInsensitiveComparison = 1 << 5, //!< Element will be compared case insensitively (must be a QString)
|
||||
LosslessMarshalling = 1 << 6 //!< Element marshalling will preserve data at the expense of size
|
||||
LosslessMarshalling = 1 << 6, //!< Element marshalling will preserve data at the expense of size
|
||||
RequiredForJson = 1 << 7 //!< Element is required when parsing from JSON
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -229,6 +230,7 @@ namespace BlackMisc
|
||||
constexpr static MetaFlags<MetaFlag::DisabledForJson> DisabledForJson {};
|
||||
constexpr static MetaFlags<MetaFlag::CaseInsensitiveComparison> CaseInsensitiveComparison {};
|
||||
constexpr static MetaFlags<MetaFlag::LosslessMarshalling> LosslessMarshalling {};
|
||||
constexpr static MetaFlags<MetaFlag::RequiredForJson> RequiredForJson {};
|
||||
//! @}
|
||||
|
||||
//! Return a CMetaMemberList of type deduced from the types of the meta members.
|
||||
|
||||
@@ -155,7 +155,7 @@ namespace BlackMisc
|
||||
const auto value = json.value(CExplicitLatin1String(member.latin1Name()));
|
||||
if (value.isUndefined())
|
||||
{
|
||||
constexpr bool required = false; //! \fixme add RequiredForJson flag in metaclass system
|
||||
constexpr bool required = decltype(member)::has(MetaFlags<RequiredForJson>());
|
||||
// QLatin1String used instead of QStringLiteral below since the latter causes an internal compiler bug
|
||||
// in GCC 8 and higher
|
||||
if (required) { throw CJsonException(QLatin1String("Missing required member '%1'").arg(member.latin1Name())); } // cppcheck-suppress knownConditionTrueFalse
|
||||
|
||||
Reference in New Issue
Block a user