You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We currently have a special condition for DateTime class, but looking at the project forks people are also extending it MongoId and MongoDate. Having an easier way to customize it would be ideal to avoid forks and customization diverging the project.
An idea would be making JsonSerializer receive a list of classname with callable to generate the output. It would be used on the unserialize portion. The current DateTime customization would live in this project since it is a php-core class. People could add it on demand.
Update docs to explain how to implement these customizations too and how to use.
The text was updated successfully, but these errors were encountered:
I couldn't get the enhanced version with composer for some reason (not in stable release).
However I could manage my date formatting issue rather simply :
use Zumba\JsonSerializer\JsonSerializer as ZumbaJsonSerializer;
class JsonSerializer extends ZumbaJsonSerializer
{
protected function serializeObject($value) {
$data = parent::serializeObject($value);
if ($data['@type']=='DateTime'){
//any changes here
$data['date'] = $value->format(\DateTime::ISO8601);
}
return $data;
}
}
Maybe not the most efficient since the formatting job is done twice, but it works (however a non standard format would require to override unserializeObject as well).
We currently have a special condition for
DateTime
class, but looking at the project forks people are also extending itMongoId
andMongoDate
. Having an easier way to customize it would be ideal to avoid forks and customization diverging the project.An idea would be making
JsonSerializer
receive a list of classname with callable to generate the output. It would be used on the unserialize portion. The currentDateTime
customization would live in this project since it is a php-core class. People could add it on demand.Update docs to explain how to implement these customizations too and how to use.
The text was updated successfully, but these errors were encountered: