I have an entity Product with a one-to-many relationship to an entity Property. When I serialise a product instance using the JMS Serialiser I get the following JSON output:
{
"id": 123,
"name": "Mankini Thong",
"properties": [{
"label": "Minimal size",
"name": "min_size",
"value": "S"
}, {
"label": "Maximum size",
"name": "max_size",
"value": "XXXL"
}, {
"label": "colour",
"name": "Colour",
"value": "Office Green"
}]
}
I try to get the serialiser to serialise the properties collection as an object in which a certain field is used as key. For instance, the name field. The desired output is:
{
"id": 123,
"name": "Mankini Thong",
"properties": {
"min_size": {
"label": "Minimal size",
"value": "S"
},
"max_size": {
"label": "Maximum size",
"value": "XXXL"
},
"colour": {
"label": "Colour",
"value": "Office Green"
}
}
}
What would be the best approach to achieve this?