Imagine I have a simple object, structured similarly to the one below:
Object (SomeClass) {
$someOtherData (array) [
...
]
$data (array) [
"key": "value",
"key": "value",
"key": "value",
"key": "value"
]
}
If I were to serialize this object with JMS Serializer to JSON, I'd get a result that has an identical structure, but with $data being on the root element, like so:
{
"someOtherData": {
...
},
"data": {
"key": "value",
"key": "value",
"key": "value",
"key": "value"
}
}
I need to have the content of the $data variable be on the root of the serialized result, i.e:
{
"someOtherData": {
...
},
"key": "value",
"key": "value",
"key": "value",
"key": "value"
}
Is this possible? If so, how?
Turns out there is an annotation for this. It's the @Inline
annotation:
use JMS\Serializer\Annotation\Inline;
// ...
/**
* @var array
*
* @Inline
*/
protected $variables;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With