panko_serializer
panko_serializer copied to clipboard
Loading dynamic field names during serialization
Assume I have a model User, and it has a field custom1
and has other fields like id, name
.
Now I have something like this:
class UserSerializer < Panko::Serializer
attributes [:id, :name, :custom1]
end
And after serialization, the response looks like this:
[
{
id: 1,
name: 'rishi'
custom1: 'c1'
},
{
id: 2,
name: 'jain'
custom1: 'c2'
}
]
Now ideally I want to change the field name custom1
to something based on some logic. So it for first object, it can be "lookup-v1" and for second object in that response, it could be "lookup-v2".
Is there a way I can achieve this?