techtalk / JiraRestClient

A simple client for Atlassian JIRA service REST API
Other
65 stars 80 forks source link

Support for custom deserializers #14

Closed fc1943s closed 8 years ago

fc1943s commented 9 years ago

Currently i have 2 jira instances, and they have different customfield IDs. I need my app to integrate to both of them, using the same CustomIssueFields class. My app.config file will decide which custom field ID will be used for each instance.

Despite my needs, this change adds flexibility to the library, someone else might find another use for it, but for me it is crucial for my app to work. I hope you guys consider it.

I know this will work only for deserialization, i will pull request the serialization part after this.

An example of how i will use it (my extension methods use JSON.NET, already tested on my local fork):

private class JsonDeserializer : IDeserializer 
{
    public T Deserialize<T>(IRestResponse response)
    {
        return response.Content.FromJson<T>(new DefaultJsonSerializerSettings(null, property =>
        {
            if (property.DeclaringType == typeof(CustomIssueFields) && property.PropertyName == "MySuiteTicket")
            {
                property.PropertyName = ConfigurationManager.AppSettings["JiraCustomFieldMySuiteTicket"];
            }
        }));
    }

    public string RootElement { get; set; }
    public string Namespace { get; set; }
    public string DateFormat { get; set; }
}

private class CustomIssueFields : IssueFields
{
   public string MySuiteTicket { get; set; }
}