I am working on a project where I am using Refit library for making Http calls and parsing the data to specific models. This works well for most of it, however, I have an issue where I have parse the Json to pre-defined models at run time. As an example the response below from the API can vary based on what actions the user of the app has to take. My question is how to parse the "actions" field from the Json to a specific model. I have pre-defined all the models for which the values can be mapped. Like I have a "ResetPassword", "TwoFactorAuthnentication" etc etc. I would like to use a TypeAdapter or something equivalent to be able to parse the value to specific model.
Any help will be greatly appreciated.
"authorizeActions": [
{
"action": "",
"required": true,
"webFallback": true
}
]
"authorizeActions": [
{
"action": "resetPassword",
"required": true,
"webFallback": true
}
]
Below is the model which I am using currently
public class AuthorizeActions
{
[JsonProperty(PropertyName = "required")]
public bool Required { get; set; }
[JsonProperty(PropertyName = "webFallback")]
public bool WebFallback { get; set; }
//Here i need to define the action , what I want is to be parsed to a
concrete class like, however the value can change, one time it can
be "ResetPassword" but it can also be "TwoFactorAuthentication" etc etc.
}