-
Notifications
You must be signed in to change notification settings - Fork 624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass additional arguments into custom serializer #1384
Comments
Could you describe the problem being solved in more detail? |
To show in more detail the capabilities of polymorphic deserialization, I will give the following example.
some of them have custom serializers
and a polymorphic serializer is
in this case, you can deserialize different JSON of different structure
|
Thank you for this example, I have a JsonContentPolymorphicSerializer like this in place for another usecase. Here I have a different problem: The root-serialname can be different. So applied to your example, the parent property itself could be named either "parentInt" or "parentString", and based on this I want to select the proper serializer. So I would want to pass these 2 serial names into the JsonContentPolymorphicSerializer so I can choose the proper serializer based on them. Currently I don't know how the same custom serializer can listen to multiple different keys (without having multiple properties). |
@KevinBassaDevelopment something like that #203? |
This combined with the information in the serializer itself which is the 'current' key that has been triggered |
In this case, your top-level serializer is actually polymorphic, since its structure is not fixed. Maybe it's better to implement it this way? |
There are a few properties like this used within many base classes. #203 will already resolve the main part. Is there any way to access the property name in
similar to |
The suggestion is to change the signature of the function |
Yes exactly. This would enable many possibilities for custom serializers, especially when combined with the new |
…he elementName to selectDeserializer.
@shanshin I created a PR for this feature, maybe you could have a look at it. |
Sorry for the delay — I saw your PR, and I'll return to it soon. Although I'm not sure these changes are really necessary for your use case. It is much easier to determine serializer by property name, yes, but without it, this task is still possible — you can check whether the |
It is mandatory for having proper data validation. In the datamodel its then just a abstract type 'value' , with whatever concrete type. In my use case there are many different options with many different validations, and knowing how the original property was named is absolutely important. It could also be These are just some random examples, I hope they help to describe why I need to get this information out of the serializer. |
Is it possible to parse data that can have multiple types, and multiple names into 1 data model?
Example JSON:
{ "doseNumberInt" = 5 }
or
{ "doseNumberMyDose" = { myDose : { value = "5" } } }
or
{ "doseNumberString" = { myDose = "5" }
The model itself has just 1 property
var doseNumber: Type?
How I would imaging a possible solution:
To achieve this, it would be required to pass additional information from the data model into the serializer (currently only SerialName?)
Is this a usecase that makes sense? Is there a way to achieve this with the current possibilities?
The text was updated successfully, but these errors were encountered: