PHP code example of kingson-de / marshal-json-serializer
1. Go to this page and download the library: Download kingson-de/marshal-json-serializer 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/ */
kingson-de / marshal-json-serializer example snippets
use KingsonDe\Marshal\AbstractObjectMapper;
use KingsonDe\Marshal\Data\FlexibleData;
class UserIdMapper extends AbstractObjectMapper {
public function map(FlexibleData $flexibleData, ...$additionalData) {
return $flexibleData->get('id');
}
}
use KingsonDe\Marshal\MarshalJson;
$json = '{"id": 123}';
$id = MarshalJson::deserializeJson($json, new UserIdMapper());
use KingsonDe\Marshal\MarshalJson;
$id = MarshalJson::deserializeJsonCallable($json, function (FlexibleData $flexibleData) {
return $flexibleData['id'];
});
use KingsonDe\Marshal\Data\FlexibleData;
use KingsonDe\Marshal\MarshalJson;
$json = '{"name": "John Doe"}';
$flexibleData = new FlexibleData(MarshalJson::deserializeJsonToData($json));
$flexibleData['name'] = 'Jane Doe';
$modifiedJson = MarshalJson::serialize($flexibleData);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.