Best way to deserialize duplicate JSON API responses (Using Newtonsoft.JSON)
I'm using a HTTP client to contact an API, and then deserializing the JSON response into an instance of its respective object type.
My issue is this - the API has two versions:
Version 1:
Version 2:
If I were to to create a class for this response, it may look like this:
As you can see, this makes it difficult to reuse the same class type for v2 data. Is there a "clean" way I to achieve using only on class type for deserialization of both API versions?
My issue is this - the API has two versions:
- Version 1: The old API, but still active, however, it's not maintained and may be missing bits of data that are present in requests made to v2 of the API.
- Version 2: The new API. Almost identical responses to v1, but all of the fields are obfuscated.
Version 1:
Version 2:
If I were to to create a class for this response, it may look like this:
As you can see, this makes it difficult to reuse the same class type for v2 data. Is there a "clean" way I to achieve using only on class type for deserialization of both API versions?