I'd like to have two different representations for the same entity using the PHP library JMSSerializer, which can easily be achieved by its groups feature.
The problem is that I have one representation where the properties of a sub object are inlined, and once they are not. It would be nice if it works somehow like this:
<?xml version="1.0" encoding="UTF-8"?>
<serializer>
<class name="SomeEntity">
<property name="structure" type="SomeOtherEntity" groups="group1" inline="true"/>
<property name="structure" type="SomeOtherEntity" groups="group2"/>
</class>
</serializer>
What I wanted to accomplish this way, was that SomeEntity
could be serialized using group1
with SomeOtherEntity
being inlined, and with group2
if SomeOtherEntity
should not be inlined, but that doesn't seem to work (I guess the name attribute is kind of unique).
A solution would be to introduce another method in combination with a VirtualProperty
, but then I would have to touch the class, which I would prefer to avoid, since it is a pure serialization issue.
Any better ideas how to solve this?