mirror of
https://github.com/oatpp/oatpp.git
synced 2024-12-09 09:10:08 +08:00
Merge pull request #494 from bamkrs/alwaysIncludeEmptyCollectionElements
Added `alwaysIncludeEmptyCollectionElements` to `Serializer`
This commit is contained in:
commit
79e7a73043
@ -74,6 +74,11 @@ public:
|
||||
*/
|
||||
bool alwaysIncludeRequired = false;
|
||||
|
||||
/**
|
||||
* Always include array or map elements, even if their value is `nullptr`.
|
||||
*/
|
||||
bool alwaysIncludeNullCollectionElements = false;
|
||||
|
||||
/**
|
||||
* If `true` - insert string `"<unknown-type>"` in json field value in case unknown field found.
|
||||
* Fail if `false`.
|
||||
@ -136,7 +141,7 @@ private:
|
||||
bool first = true;
|
||||
|
||||
for(auto& value : *list) {
|
||||
if(value || serializer->getConfig()->includeNullFields) {
|
||||
if(value || serializer->getConfig()->includeNullFields || serializer->getConfig()->alwaysIncludeNullCollectionElements) {
|
||||
(first) ? first = false : stream->writeSimple(",", 1);
|
||||
serializer->serialize(stream, value);
|
||||
}
|
||||
@ -161,7 +166,7 @@ private:
|
||||
|
||||
for(auto& pair : *map) {
|
||||
const auto& value = pair.second;
|
||||
if(value || serializer->getConfig()->includeNullFields) {
|
||||
if(value || serializer->getConfig()->includeNullFields || serializer->getConfig()->alwaysIncludeNullCollectionElements) {
|
||||
(first) ? first = false : stream->writeSimple(",", 1);
|
||||
const auto& key = pair.first;
|
||||
serializeString(stream, key->getData(), key->getSize());
|
||||
|
Loading…
Reference in New Issue
Block a user