Skip to content

Release 1.8

Choose a tag to compare

@igorpocta igorpocta released this 28 Feb 18:14
· 64 commits to main since this release

Null values included in normalization output by default

Breaking change: Normalizer now includes properties with null values in toArray() / toJson() output by default. Previously, null properties were silently omitted.

Before

{"name": "John"}

After

{"name": "John", "email": null, "address": null}

Opt-out

To preserve the old behavior, use skipNullValues:

$mapper = new Mapper(new MapperOptions(skipNullValues: true));

Nested objects

Nested objects with null properties now correctly serialize as a JSON object, not as an empty array:

// Before: {"address": []}
// After:  {"address": {"street": null, "city": null}}

Changed files

  • Normalizer — shouldIncludeNull() wired to skipNullValues
  • Mapper — passes MapperOptions::skipNullValues to Normalizer and TypeResolver
  • TypeResolver / ObjectType — propagates the setting to nested normalizations