I've an entity that stores a property inside an array. Here an example.
{
"id": 42,
"superheroes": {
"hero": {
"name": "Batman"
},
"antihero": {
"name": "Joker"
}
},
"id": 43,
"superheroes": {
"hero": {
"name": "Bing"
},
"antihero": {
"name": "Flop"
}
},
}
When I tried to represent this kind of information using api-platform, I got this:
id, superhero.hero.name, superhero.antihero.name
42, Batman, Joker
What I need instead is this kind of output. I mean, ... Each line must be exploded into more lines.
id, name
42, Batman
42, Joker
43, Bing
43, Flopp
I am trying to solve the issue creating a normalizer. But this attempt give me strange ouput:
/**
* @param AppEntityInsurance $object
* @param string|null $format
* @param array $context
* @return array|ArrayObject|bool|float|int|string|null
*/
public function normalize($object, string $format = null, array $context = [])
{
return [
[
$object->getId(),
$object->getSuperheroes()['hero']['name'],
], [
$object->getId(),
$object->getSuperheroes()['antihero']['name'],
],
];
}
0.0,0.1,1.0,1.1
42,Batman,42,Batman
43,Bing,43,Bing