PHP code example of lookyman / json-mapper
1. Go to this page and download the library: Download lookyman/json-mapper library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lookyman / json-mapper example snippets
use Lookyman\JsonMapper\MapperBuilder
use PHPUnit\Framework\Assert;
class Foo
{
public function __construct(public string $foo)
{
}
}
class Bar
{
public function __construct(public Foo $first)
{
}
}
$result = (new MapperBuilder())
->build()
->map(Bar::class, '{"first":{"foo":"wtf"}}');
Assert::assertEquals(
new Bar(new Foo('wtf')),
$result,
);