serializer
serializer copied to clipboard
Deserialize with other JSON-Keys than Serialization
Q | A |
---|---|
Bug report? | no |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Just quick question:
Is there a way for different mapping key for deserialization and serialization?
Example: JSON-Message with { "name": "hello", "age": 30 }
deserialized to entity-object with annotations
@Serializer\SerializedName("name") protected $name;
@Serializer\SerializedName("age") protected $age;
=> works as expected.
Serialization should output JSON for the same entity but with other JSON-keys like:
JSON-Message with { "hisNameIs": "hello", "hisAgeIs": 30 }
If I change the @Serializer\SerializedName to "hisNameIs" it would ouput correctly but deserialization would not work anymore.
Currently there are no ways to define different naming schemes when serializing/deserializing out of the box.
You can implement https://github.com/schmittjoh/serializer/blob/1.x/src/JMS/Serializer/Naming/AdvancedNamingStrategyInterface.php and do it by your self by examining the Context.