-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow JSON normalizer to set JSON formatting options
By default, the JSON normalizer will only use `JSON_THROW_ON_ERROR` to encode non-boolean scalar values. There might be use-cases where projects will need flags like `JSON_JSON_PRESERVE_ZERO_FRACTION`. This can be achieved by passing these flags to the new `JsonNormalizer::withOptions()` method: ```php namespace My\App; $normalizer = (new \CuyZ\Valinor\MapperBuilder()) ->normalizer(\CuyZ\Valinor\Normalizer\Format::json()) ->withOptions(\JSON_PRESERVE_ZERO_FRACTION); $lowerManhattanAsJson = $normalizer->normalize( new \My\App\Coordinates( longitude: 40.7128, latitude: -74.0000 ) ); // `$lowerManhattanAsJson` is a valid JSON string representing the data: // {"longitude":40.7128,"latitude":-74.0000} ``` The method accepts an int-mask of the following `JSON_*` constant representations: - `JSON_HEX_QUOT` - `JSON_HEX_TAG` - `JSON_HEX_AMP` - `JSON_HEX_APOS` - `JSON_INVALID_UTF8_IGNORE` - `JSON_INVALID_UTF8_SUBSTITUTE` - `JSON_NUMERIC_CHECK` - `JSON_PRESERVE_ZERO_FRACTION` - `JSON_UNESCAPED_LINE_TERMINATORS` - `JSON_UNESCAPED_SLASHES` - `JSON_UNESCAPED_UNICODE` `JSON_THROW_ON_ERROR` is always enforced and thus is not accepted. See official doc for more information: https://www.php.net/manual/en/json.constants.php
- Loading branch information
Showing
5 changed files
with
200 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters