Answer the question
In order to leave comments, you need to log in
How to reduce json nesting from JMS serializer?
I can't figure out what to do with connections. OneToOne - in the first entity (user) there is a tags field, which is connected to another table (tag_string) in which the list of tags is cached as a comma-separated string. At the output, I wanted to get user data with a tag line field from the second table.
But as I understand it, there is a nesting of the type
{
name: 'Ivan',
age: 20,
tags: {
str: "tag1, tag2, tag3 ..."
}
}
/**
* @View()
* @return array
*/
public function getAction(User $user)
{
return $user;
}
Answer the question
In order to leave comments, you need to log in
You can try using virtual methods (VirtualProperty):
class User {
...
/**
* @Serializer\VirtualProperty()
* @Serializer\SerializedName("tags")
*/
public function getTags()
{
return explode(',', $this->tags->getStr());
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question