Skip to content

Commit 0dc2de8

Browse files
author
Enno Woortmann
committed
Skip optional values which were not provided in the data in the serialization result to avoid generating incompatible serialized values due to NULL fields (wol-soft/php-json-schema-model-generator#76)
1 parent 5b63309 commit 0dc2de8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Traits/SerializableTrait.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ public function toArray(array $except = [], int $depth = 512)
6161
$depth--;
6262
$modelData = [];
6363

64+
if (isset($this->_skipNotProvidedPropertiesMap)) {
65+
$except = array_merge(
66+
$except,
67+
array_diff($this->_skipNotProvidedPropertiesMap, array_keys($this->_rawModelDataInput))
68+
);
69+
}
70+
6471
foreach (get_class_vars(get_class($this)) as $key => $value) {
6572
if (in_array($key, $except) || strstr($key, '_') !== false) {
6673
continue;

0 commit comments

Comments
 (0)