Exemple #1
0
        /// <summary>
        /// Deserialize json JObject to C# object instance based on C# type.
        /// </summary>
        /// <param name="jobject">Json JObject data to deserialize.</param>
        /// <param name="type">SugarCrm C# model type.</param>
        /// <returns>Object instance.</returns>
        public static object Deserialize(JObject jobject, Type type)
        {
            var settings = new JsonSerializerSettings();
            DeserializerExceptionsContractResolver resolver = DeserializerExceptionsContractResolver.Instance;

            resolver.JsonObjectToDeserialize = jobject;
            settings.ContractResolver        = resolver;

            return(JsonConvert.DeserializeObject(jobject.ToString(), type, settings));
        }
Exemple #2
0
        /// <summary>
        /// Deserialize json string to C# object instance based on C# type.
        /// </summary>
        /// <param name="content">Json data to deserialize.</param>
        /// <param name="type">SugarCrm C# model type.</param>
        /// <returns>Object instance.</returns>
        public static object Deserialize(string content, Type type)
        {
            var settings = new JsonSerializerSettings();
            DeserializerExceptionsContractResolver resolver = DeserializerExceptionsContractResolver.Instance;

            resolver.JsonToDeserialize = content;
            settings.ContractResolver  = resolver;

            return(JsonConvert.DeserializeObject(content, type, settings));
        }
 /// <summary>
 /// Initializes static members of the <see cref="DeserializerExceptionsContractResolver" /> class.
 /// </summary>
 static DeserializerExceptionsContractResolver()
 {
     instance = new DeserializerExceptionsContractResolver();
 }