phpfluent / jsonserializer
JSON Serializer implementation.
Installs: 20
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 2
Open Issues: 0
pkg:composer/phpfluent/jsonserializer
Requires
- crodas/notoj: dev-master
Requires (Dev)
- phpunit/phpunit: 4.8.28
This package is auto-updated.
Last update: 2025-09-27 04:42:04 UTC
README
JSON Serializer implementation.
Install:
composer.phar require phpfluent/jsonserializer:dev-master
Usage:
<?php use PHPFluent\JSONSerializer\Serializer; class Nested extends Serializer { /** * @PHPFluent\JSONSerializer\Attribute */ private $array; public function setArray(array $array) { $this->array = $array; return $this; } } class MyFancyClass extends Serializer { /** * @PHPFluent\JSONSerializer\Attribute */ private $email; /** * @PHPFluent\JSONSerializer\Attribute */ private $nested; private $iWontBeSerialized; public function setEmail($email) { if ( ! filter_var($email, FILTER_VALIDATE_EMAIL)) { throw new \InvalidArgumentException("Invalid email"); } $this->email = $email; return $this; } public function setNested(Nested $nested) { $this->nested = $nested; return $this; } } $nested = (new Nested)->setArray(array(1, 2, 3)); $fancy = (new MyFancyClass)->setEmail("foo@bar.com")->setNested($nested); json_encode($fancy); /* $serialized = json_encode( (new MyFancyClass)->setEmail("foo@bar.com")->setNested( (new Nested)->setArray(array(1, 2, 3)) ); ); */
Test:
cd phpfluent/jsonserializer composer.phar install --dev make test