Answer the question
In order to leave comments, you need to log in
How to display only entity_id in JMSSerializer instead of whole entity?
Hello.
There was a task to organize a trivial RESTful API for internal use, I connected FOSRestBundle, but I don’t use it 100% - I only took View from there.
There was a question with data de/serialization: I have entities Group (id, name) and Item with fields (id, name, group).
First I do a POST /groups with a body
{
"name": "foo"
}
[
{
"id": "8215471f-834b-49fa-8a32-ff4a2f849bdf",
"name": "foo"
}
]
{
"name": "bar",
"group": "8215471f-834b-49fa-8a32-ff4a2f849bdf"
}
{
"name": "bar",
"group": {
"id": "8215471f-834b-49fa-8a32-ff4a2f849bdf",
"name": "foo"
}
}
{
"name": "bar",
"group": "8215471f-834b-49fa-8a32-ff4a2f849bdf"
}
Answer the question
In order to leave comments, you need to log in
Everything is right with you, you cannot get it like this in the standard way:
{
"name": "bar",
"group": "8215471f-834b-49fa-8a32-ff4a2f849bdf"
}
since the item group is a link, so you get its id as an array/object.
Or have I misconfigured the serializer?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question