QSerializer
QSerializer copied to clipboard
QSerializer Enhancements and Fixes
Overview of Updates
This PR introduces several improvements to the QSerializer library, enhancing serialization capabilities and user experience. Main changes include:
- Conditional definition support for
QJsonDocumentmode - Code structure optimization and warning reduction
- Enhanced
std::optional<T>JSON/XML serialization support - Empty value and null reference skipping functionality
Detailed Changes
Serialization Options Enhancement
- Implemented comprehensive skipping mechanism for empty values, null values, and null literals
- Added class-level and member-level serialization option controls
- Introduced
shouldSkipMemberEmpty,shouldSkipMemberNull, andshouldSkipMemberNullLiteralsmethods for fine-grained control
Macro Definition Optimization
- Refactored
QS_DERIVED_META_OBJECT_METHODand related macros for code consistency - Added
QS_FIELD_DEFAULTandQS_OBJECT_DEFAULTmacros to support default value setting - Optimized
QSERIALIZABLEmacro definition
C++17 Compatibility
- Added C++17-based conditional compilation logic
- Utilized
inline staticmember variables for improved implementation efficiency in C++17 - Maintained backward compatibility with older C++ standards
Optional Type Support
- Enhanced JSON and XML serialization handling for
std::optional<T> - Added dedicated macros for optional types:
QS_JSON_FIELD_OPT,QS_XML_FIELD_OPT, etc. - Implemented optional object type serialization:
QS_JSON_OBJECT_OPT,QS_XML_OBJECT_OPT
Other Optimizations
- Converted QSerializer to a header-only INTERFACE library, improving ease of use
- Fixed Qt6 support issues
- Improved static function methods, including adding static
fromJsonfunctionality
Usage Example
// Using class-level settings to skip empty values and null
QS_CLASS_BEGIN(MySerializableClass)
QS_INTERNAL_SKIP_EMPTY_AND_NULL
QS_FIELD(QString, normalString)
QS_FIELD_OPT(int, optionalInt)
// Member-level settings
QS_FIELD(QStringList, emptyListToSkip)
QS_INTERNAL_MEMBER_SKIP_EMPTY(emptyListToSkip)
QS_CLASS_END
In this PR, my primary focus is to introduce the QS_FIELD_DEFAULT macro and improve code structure optimization while reducing warnings, as these are key enhancements for the QSerializer library. Other changes, such as QS_FIELD_OPT and related optional type support macros (e.g., QS_FIELD_OPT, QS_INTERNAL_SKIP_EMPTY_AND_NULL), are part of my own requirements. If these optional type features are not needed by the project, I’m happy to open a separate PR to remove them.
Let me know if any adjustments are required!