diff --git a/README.md b/README.md index bebdad1f..e1517a9e 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,7 @@ **News** -- Hey, meet the new oatpp version `1.2.5`! See the [changelog](changelog/1.2.5.md) for details. -- Check out the new oatpp ORM - read more [here](https://oatpp.io/docs/components/orm/). +- Hey, the new oatpp version `1.3.0` will soon be merged to master! Follow the [changelog](https://github.com/oatpp/oatpp/blob/v1.3.0/changelog/1.3.0.md) for details, and prepare for migration. *[Follow PR](https://github.com/oatpp/oatpp/pull/453)*. --- diff --git a/src/oatpp-test/UnitTest.hpp b/src/oatpp-test/UnitTest.hpp index b04dbc83..6e8a33cf 100644 --- a/src/oatpp-test/UnitTest.hpp +++ b/src/oatpp-test/UnitTest.hpp @@ -27,6 +27,7 @@ #include #include "oatpp/core/base/Environment.hpp" +#include "oatpp/core/macro/basic.hpp" namespace oatpp { namespace test { @@ -92,8 +93,10 @@ public: #define OATPP_RUN_TEST_0(TEST) \ oatpp::test::UnitTest::runTest(1) + #define OATPP_RUN_TEST_1(TEST, N) \ oatpp::test::UnitTest::runTest(N) + /** * Convenience macro to run test.
* Usage Example:
diff --git a/src/oatpp/parser/json/mapping/Serializer.cpp b/src/oatpp/parser/json/mapping/Serializer.cpp index 6a6e3a8f..23bdb2e6 100644 --- a/src/oatpp/parser/json/mapping/Serializer.cpp +++ b/src/oatpp/parser/json/mapping/Serializer.cpp @@ -155,11 +155,12 @@ void Serializer::serializeObject(Serializer* serializer, ); auto fields = dispatcher->getProperties()->getList(); auto object = static_cast(polymorph.get()); + auto config = serializer->m_config; for (auto const& field : fields) { auto value = field->get(object); - if(value || serializer->m_config->includeNullFields) { + if (value || config->includeNullFields || (field->info.required && config->alwaysIncludeRequired)) { (first) ? first = false : stream->writeSimple(",", 1); serializeString(stream, field->name, std::strlen(field->name), serializer->m_config->escapeFlags); stream->writeSimple(":", 1); diff --git a/src/oatpp/parser/json/mapping/Serializer.hpp b/src/oatpp/parser/json/mapping/Serializer.hpp index aa80cc2a..7ef50680 100644 --- a/src/oatpp/parser/json/mapping/Serializer.hpp +++ b/src/oatpp/parser/json/mapping/Serializer.hpp @@ -66,9 +66,15 @@ public: /** * Include fields with value == nullptr into serialized json. + * Field will still be included when field-info `required` is set to true and &id:alwaysIncludeRequired is set to true. */ bool includeNullFields = true; + /** + * Always include required fields (set in in DTO_FIELD_INFO) even if they are `value == nullptr` + */ + bool alwaysIncludeRequired = false; + /** * If `true` - insert string `""` in json field value in case unknown field found. * Fail if `false`.