I am trying to add support for the expand feature that stripe.com has implemented into their api but not sure how to approach this. Basically if you send a request they will return an object that has a "FK" id to another object. If you send the request with expand[]=object it will instead send over the actual object instead of the id. My problem is they both use the same property name.
C# object
public class MyObject
{
[JsonProperty("object_id")]
public int Id {get;set;}
[JsonProperty("sub_object"]
public string SubObjectId {get;set;}
[JsonProperty("sub_object"]
public SubObject SubObject {get;set;} // this is the object
}
Example Json with Id
{
object_id : "1",
sub_object: "12345"
{
Example Json with Object instead
{
object_id : "1",
sub_object: {
obj_id : "1",
prop : "whatever"
}
}
Ideally I wouldn't have to create a separate object for each instance as some of these objects have multiple properties that can be expanded. I would like to cal out to the method have it return the json, some how check if sub_object is just a string then map it to the SubObjectId field and if the sub_object is an object then have it map to the SubObject field instead.
I understand that you cannot have a C# object with multiple properties mapped to a single c# property so I am kinda clueless at this point.