I am deserializing yahoo contacts api’s json response everything is going good but I am getting issue in one field fields, its a array but in all elements value is different different, how can handle it. In two fields this is string and in other element object. here is my sample json
"fields": [
{
"created": "2008-12-29T13:47:21Z",
"updated": "2008-12-29T13:47:21Z",
"uri": "http://social.yahooapis.com/v1/user/ASASASASASASA/contact/8/email/18",
"id": "18",
"type": "email",
"value": "papi@ymail.com",
"editedBy": "OWNER"
},
{
"created": "2010-03-30T07:02:04Z",
"updated": "2011-06-25T05:01:51Z",
"uri": "http://social.yahooapis.com/v1/user/ASASASASASASA/contact/8/guid/42",
"id": "42",
"type": "guid",
"value": "BMM5JTQVDB7G4EBPO2D5ESE3TI",
"editedBy": "OWNER",
"isConnection": "false"
},
{
"created": "2008-12-29T13:47:21Z",
"updated": "2008-12-29T13:47:21Z",
"uri": "http://social.yahooapis.com/v1/user/ASASASASASASA/contact/8/name/17",
"id": "17",
"type": "name",
"value": {
"givenName": "Hitesh",
"middleName": null,
"familyName": "Lohar",
"prefix": null,
"suffix": null,
"givenNameSound": null,
"familyNameSound": null
},
"editedBy": "OWNER"
}
]
I created following class for Field
public class YahooField
{
[JsonProperty("created")]
public string Created { get; set; }
[JsonProperty("updated")]
public string Updated { get; set; }
[JsonProperty("uri")]
public string Uri { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
//here confusion
//[JsonProperty("value")]
//public (String or class) Value { get; set; }
[JsonProperty("editedBy")]
public string EditedBy { get; set; }
[JsonProperty("isConnection")]
public string IsConnection { get; set; }
}
The value property is just another object.
Create a new class called ValueField and add some properties:
And add this class as a property to your YahooField class
You should write your own contract resolver to detect if the property Value is of type String or not. This way you can interrupt the default behaviour and implement your own logic.
Just derive your CustomContractResolver from DefaultContractResolver and override the virtual methods you need for your implementation.
You can set your custom contract resolver by doing the following: