Given some json that looks like
{
"id":"123_678",
"fs_123_678":
{
"title":"Apple Parts",
"data": 134
}
}
I'd like to deserialize it into the following classes
public class Result
{
public string Id {get; set;}
public ResultInfo Info {get; set;}
}
public class ResultInfo
{
public string Title {get; set;}
public int Data {get; set;}
}
... but that second property (fs_123_678
) is not a fixed name. I've looked at other similar posts on SO here, and the common solution is to use a IDictionary<string, MyPoco>
however, that only works when the variable data is not at the root level. The name of the property is 100% predictable, and I could describe in code what it will be for a given JSON response based off of values used in the source HTTP request. The trick is, how do I let the JSON deseralizer in on the business rule around what it will be called for this given deserialization? I basically need something that would act like [JsonProperty(PropertyName = *insert logic here*)]
(which of course isn't possible).
What's a reasonable way to approach this, all while retaining the "for free" strong-typed deserialization of the rest of the object?