Hi,
I am trying to understand the benefit of inheriting the model class with
Dictionary<String, Object>
in web api project.
Below is the sample of model class.
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace IO.Swagger.Model {
[DataContract]
public class ApiErrorResponse : Dictionary<String, Object> {
[DataMember(Name="Errors", EmitDefaultValue=false)]
[JsonProperty(PropertyName = "Errors")]
public List<IntegrationErrorDto> Errors { get; set; }
[DataMember(Name="CorrelationKey", EmitDefaultValue=false)]
[JsonProperty(PropertyName = "CorrelationKey")]
public string CorrelationKey { get; set; }
public override string ToString() {
var sb = new StringBuilder();
sb.Append("class ApiErrorResponse {\n");
sb.Append(" Errors: ").Append(Errors).Append("\n");
sb.Append(" CorrelationKey: ").Append(CorrelationKey).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
public new string ToJson() {
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
}
}
Each model class are inherited form
Dictionary<String, Object>
Ech model class override the
ToString() method
each model class have
ToJson()
method.
Please help me to figure out the situation in which i can follow the same approach
What I have tried:
What is notice that
ToJson()
METHOD EASILY SERIALIZE THE OBJECT DATA.