I'm deserializing some very dirty data that I don't have any control over
Example:
Copy code
{
"field1":"a field that's always there"
"field2":"a field that's sometimes there, other times not and the content varies from Boolean to String to Dates to numbers"
}
Is it possible to have
ignoreUnknownKeys=false
and then have a list of fields that I can ignore?
I want it to throw an error if they send for example JSON that now has a
field3
, but I don't want to care about
field2
and I definitely don't want it in my model.
I'm already using a custom JsonContentPolymorphicSerializer so that I can switch between different types for one of the other fields
a
Adam S
12/13/2022, 11:40 AM
the first suggestion that springs to mind would be
• set the type of
field2
to be
JsonElement
,
• and have
field2
defined in code but document it as
@Deprecated
- perhaps even with the visibility set to ‘hidden’