Custom ModelsSerializer
Closed this issue · 9 comments
First of all, thank you for this wonderful library. It allows creating a simple layer between reduxObject and the views. Currently, I have a specific use case for building the JSON and need some guidance.
Property mappers give the flexibility to structure the data for the serializer, but is there a way to change how to relationships will be built in JSON?
Specifically, I want to preserve attributes in a relationship model, but only id and type is parsed.
I don't want to include that data in the included array, but pass it inline.
Is there a way to tackle this with jsona?
@renatoruk
Hi, thank you!
For now it's impossible, relationship object is explicitly set in ModelsSerializer.ts
May be it should use property mapper with new method - 'getRelationships', but current 'getRelationships' should be renamed to 'getRelations'
So getRelations would be called here?
What about exporting ModelsSerializer, extending it and passing it to Jsona constructor?
This is the JSON structure I am aiming for.
{
"data": {
"id": "",
"type": "foo",
"attributes": {
"a": "b"
},
"relationships": {
"bar": {
"id": "",
"type": "bar",
"attributes": {
"c": "d"
}
}
}
}
}
@renatoruk
Hi! Sorry for delay, I had a lot to do
So getRelations would be called here?
Yes
What about exporting ModelsSerializer, extending it and passing it to Jsona constructor?
We can do so
Will you make PR?
I implemented something on top of the serialized model that does the same thing, but this would be a better approach. Will let you know if it's feasible to do it this way.
I've managed to find a workaround for now outside the library. If the requirements change, I'll make a PR. Thank you for your help 🙏
You're welcome!
Hey @olosegres would you still be open to a PR supporting this behavior? Similarly, an identical approach for JsonDeserializer
as well? Have use cases that I unfortunately can't make work utilizing this awesome library otherwise.
@renatoruk Hi
What about exporting ModelsSerializer, extending it and passing it to Jsona constructor?
Released in 1.6.0
Thanks @jordandukart for the PR #38