From c80047b6bd8cc6428eac3f8a0bdf0caea7cd93ed Mon Sep 17 00:00:00 2001 From: lganzzzo Date: Thu, 14 Oct 2021 02:30:55 +0300 Subject: [PATCH 1/4] UnitTest.hpp fix includes --- src/oatpp-test/UnitTest.hpp | 3 +++ 1 file changed, 3 insertions(+) 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:
From cf9530ced5e31d46a8e3278f9573be08fccf915a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt-Alexander=20Mokro=C3=9F?= Date: Thu, 14 Oct 2021 11:05:35 +0200 Subject: [PATCH 2/4] Add option to include required fields in JSON even if `value == nullptr` and `includeNullFields == false`. --- src/oatpp/parser/json/mapping/Serializer.cpp | 3 ++- src/oatpp/parser/json/mapping/Serializer.hpp | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/oatpp/parser/json/mapping/Serializer.cpp b/src/oatpp/parser/json/mapping/Serializer.cpp index cd7c99d1..bd33cb84 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 dispatcher = static_cast(polymorph.valueType->polymorphicDispatcher); auto fields = dispatcher->getProperties()->getList(); auto object = static_cast(polymorph.get()); + auto config = serializer->getConfig(); for (auto const& field : fields) { auto value = field->get(object); - if(value || serializer->getConfig()->includeNullFields) { + if (value || config->includeNullFields || (field->info.required && config->honorRequired)) { (first) ? first = false : stream->writeSimple(",", 1); serializeString(stream, (p_char8)field->name, std::strlen(field->name)); stream->writeSimple(":", 1); diff --git a/src/oatpp/parser/json/mapping/Serializer.hpp b/src/oatpp/parser/json/mapping/Serializer.hpp index 7174d9e8..967bdb88 100644 --- a/src/oatpp/parser/json/mapping/Serializer.hpp +++ b/src/oatpp/parser/json/mapping/Serializer.hpp @@ -65,9 +65,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:honorRequired is set to true. */ bool includeNullFields = true; + /** + * Honor required fields in DTO_FIELD_INFO and include required fields even if they are `value == nullptr` + */ + bool honorRequired = false; + /** * If `true` - insert string `""` in json field value in case unknown field found. * Fail if `false`. From ac2862d9845541e20d74d36f98b908ec9641a0c9 Mon Sep 17 00:00:00 2001 From: Leonid Stryzhevskyi Date: Fri, 15 Oct 2021 02:00:23 +0300 Subject: [PATCH 3/4] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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)*. --- From defcc35e093fcfd71cc191cba618f840385ae7c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt-Alexander=20Mokro=C3=9F?= Date: Fri, 15 Oct 2021 10:49:24 +0200 Subject: [PATCH 4/4] Renamed `honorRequired` to `alwaysIncludeRequired`. --- src/oatpp/parser/json/mapping/Serializer.cpp | 2 +- src/oatpp/parser/json/mapping/Serializer.hpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/oatpp/parser/json/mapping/Serializer.cpp b/src/oatpp/parser/json/mapping/Serializer.cpp index bd33cb84..f1acd5f4 100644 --- a/src/oatpp/parser/json/mapping/Serializer.cpp +++ b/src/oatpp/parser/json/mapping/Serializer.cpp @@ -160,7 +160,7 @@ void Serializer::serializeObject(Serializer* serializer, for (auto const& field : fields) { auto value = field->get(object); - if (value || config->includeNullFields || (field->info.required && config->honorRequired)) { + if (value || config->includeNullFields || (field->info.required && config->alwaysIncludeRequired)) { (first) ? first = false : stream->writeSimple(",", 1); serializeString(stream, (p_char8)field->name, std::strlen(field->name)); stream->writeSimple(":", 1); diff --git a/src/oatpp/parser/json/mapping/Serializer.hpp b/src/oatpp/parser/json/mapping/Serializer.hpp index 967bdb88..ab754624 100644 --- a/src/oatpp/parser/json/mapping/Serializer.hpp +++ b/src/oatpp/parser/json/mapping/Serializer.hpp @@ -65,14 +65,14 @@ public: /** * Include fields with value == nullptr into serialized json. - * Field will still be included when field-info `required` is set to true and &id:honorRequired is set to true. + * Field will still be included when field-info `required` is set to true and &id:alwaysIncludeRequired is set to true. */ bool includeNullFields = true; /** - * Honor required fields in DTO_FIELD_INFO and include required fields even if they are `value == nullptr` + * Always include required fields (set in in DTO_FIELD_INFO) even if they are `value == nullptr` */ - bool honorRequired = false; + bool alwaysIncludeRequired = false; /** * If `true` - insert string `""` in json field value in case unknown field found.