@@ -33,6 +33,21 @@ namespace Intuit.Ipp.Utility
3333 /// </summary>
3434 public class JsonObjectSerializer : IEntitySerializer
3535 {
36+ private static readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings ( )
37+ {
38+ Converters =
39+ {
40+ new ObjectToEnumConverter ( ) ,
41+ new IntuitConverter ( )
42+ } ,
43+ NullValueHandling = NullValueHandling . Ignore ,
44+ MissingMemberHandling = MissingMemberHandling . Error ,
45+ DateFormatHandling = DateFormatHandling . IsoDateFormat ,
46+ DateTimeZoneHandling = DateTimeZoneHandling . Utc ,
47+ DateFormatString = "yyyy-MM-ddTHH:mm:ssK" ,
48+ MaxDepth = 256 ,
49+ } ;
50+
3651 /// <summary>
3752 /// Initializes a new instance of the <see cref="JsonObjectSerializer"/> class.
3853 /// </summary>
@@ -65,20 +80,10 @@ public JsonObjectSerializer(ILogger idsLogger)
6580 public string Serialize ( object entity )
6681 {
6782 string data = string . Empty ;
68- JsonSerializerSettings settings = new JsonSerializerSettings ( ) ;
69- settings . Converters . Add ( new ObjectToEnumConverter ( ) ) ;
70- settings . Converters . Add ( new IntuitConverter ( ) ) ;
71-
72- settings . NullValueHandling = NullValueHandling . Ignore ;
73- settings . MissingMemberHandling = MissingMemberHandling . Error ;
74- settings . DateFormatHandling = DateFormatHandling . IsoDateFormat ;
75- settings . DateTimeZoneHandling = DateTimeZoneHandling . Utc ;
76- settings . DateFormatString = "yyyy-MM-ddTHH:mm:ssK" ;
77- settings . MaxDepth = 256 ;
7883
7984 try
8085 {
81- data = JsonConvert . SerializeObject ( entity , settings ) ;
86+ data = JsonConvert . SerializeObject ( entity , _jsonSettings ) ;
8287 }
8388 catch ( Exception ex )
8489 {
@@ -103,21 +108,13 @@ public object Deserialize<T>(string message)
103108 {
104109 object deserializedObject = null ;
105110
106- // Initialize serialize for object
107- JsonSerializerSettings settings = new JsonSerializerSettings ( ) ;
108- settings . Converters . Add ( new ObjectToEnumConverter ( ) ) ;
109- settings . Converters . Add ( new IntuitConverter ( ) ) ;
110-
111- settings . NullValueHandling = NullValueHandling . Ignore ;
112- settings . MissingMemberHandling = MissingMemberHandling . Ignore ;
113-
114111 try
115112 {
116113 // de serialization of message.
117114 /* JObject o = JObject.Parse(message);
118115 string key = o.Properties().Select(p => p.Name).Single();
119116 string entityString = o[key].ToString();*/
120- deserializedObject = JsonConvert . DeserializeObject < T > ( message , settings ) ;
117+ deserializedObject = JsonConvert . DeserializeObject < T > ( message , _jsonSettings ) ;
121118 }
122119 catch ( SystemException ex )
123120 {
0 commit comments