I have a model with attribute like this:
[
"$type" => "TestCollection",
"$id" => "f3023064-feea-11e4-8147-28d2442a84f9",
"field_a" => "a1",
"field_b" => "b1",
]
When I want to call json_decode($model) it returns an empty object:
I know that JsonKit\JsonSerializer interface is used as a contract of Norm\Model to customize the model's JSON representation when decoded with json_decode() refer to this manual.
But when I change the contract of Norm\Model with JsonSerializable (instead of JsonKit\JsonSerializer). It returns:
{"$type":"TestCollection","$id":"404c6a00-feec-11e4-9b41-28d2442a84f9","field_a":"a1","field_b":"b1"}
This is modified Norm\Model declaration:
class Model implements \JsonKit\JsonSerializer, ArrayAccess // before
{
// ...
}
class Model implements \JsonSerializable, ArrayAccess // after
{
// ...
}
Here is a screenshot before and after I change the contract:

I know, this is dilemma, because JsonSerializable interface is only supported in PHP 5.4. Should we upgrade the minimum requirement? This is some articles for your consideration to upgrade the minimum requirement to PHP 5.4:
I didn't mean to change the minimum requirement. IMHO, if you really want to support PHP 5.3, I think JsonKit\JsonSerializer implementation (json_decode($model)-ing feature) is not used anymore (should we remove it?), since this feature will break in PHP 5.4. Or we can just upgrade the minimum requirement, and replace the JsonKit\JsonSerializer contract with \JsonSerializable.
Thanks for your very kind attention.
I have a model with
attributelike this:When I want to call
json_decode($model)it returns an empty object:I know that
JsonKit\JsonSerializerinterface is used as a contract ofNorm\Modelto customize themodel's JSON representation when decoded withjson_decode()refer to this manual.But when I change the contract of
Norm\ModelwithJsonSerializable(instead ofJsonKit\JsonSerializer). It returns:This is modified
Norm\Modeldeclaration:Here is a screenshot before and after I change the contract:

I know, this is dilemma, because
JsonSerializableinterface is only supported in PHP 5.4. Should we upgrade the minimum requirement? This is some articles for your consideration to upgrade the minimum requirement to PHP 5.4:I didn't mean to change the minimum requirement. IMHO, if you really want to support PHP 5.3, I think
JsonKit\JsonSerializerimplementation (json_decode($model)-ing feature) is not used anymore (should we remove it?), since this feature will break in PHP 5.4. Or we can just upgrade the minimum requirement, and replace theJsonKit\JsonSerializercontract with\JsonSerializable.Thanks for your very kind attention.