Download the PHP package thiagocordeiro/serializer without Composer
On this page you can find all versions of the php package thiagocordeiro/serializer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package serializer
PHP Serializer
This package allows you to parse json objects into php classes without the overhead of annotations, it checks for php object constructor and creates cache classes to convert json into a given class.
How to use
For Symfony projects a bundle is available at serializer-bundle
For Laravel projects a package is available at laravel-serializer
otherwise the package is available on composer:
PHP Serializer does not use setters, so your class must have a constructor with all properties coming from the json.
Basic example (Using getters)
Basic example (Using readonly properties)
Once you have your class, you can convert json string to it, ex.
The opposite way, ex.
Complex object construction - Objects
Constructors can also have arrays and other classes on it , the other class must follow same rules, for ex.
for this example a json string could contain or not address
property:
or
Complex object construction - Arrays
Arrays are also welcome, but since there is no way to determine on the array type on object constructor, arrays require you to write php annotation, a simple doc bloc is everything it needs to deserialize any json string, ex
A json for this class would be:
Default values
By default all non-provided values will be filled with null
, if the property is not nullable then you a TypeError
will be thrown, but a property can also have a default value and in case it is not given, the default value will be used, ex.
A json without type
would result an object with $type = 'user'
.
Note: Default value will only be used in case it is not provided, if it is provided as null
then null
will be the value.
Constructor with arguments
Constructor with DateTime/DateTimeImmutable
Contributing
Feel free to open issues or submit PRs
Supporting
If you feel like supporting changes then you can send donations to the address below.
Bitcoin Address: bc1qfyudlcxqnvqzxxgpvsfmadwudg4znk2z3asj9h
All versions of serializer with dependencies
ext-json Version *