private object DeserializeJsonPlainValueObject(JsonValueObject plainValueObject, Type targetType) { if (JsonEncoder.IsNullValue(plainValueObject)) { return(null); } else { return(plainValueObject.ToString().ConvertTo(targetType)); } }
private object DeserializeJsonDictionaryObject(JsonDictionaryObject dictionaryObject) { var instance = Activator.CreateInstance(Type); foreach (var element in dictionaryObject.Elements) { JsonProperty jsonProperty; JsonProperties.TryGetValue(element.Key, out jsonProperty); if (jsonProperty == null) { continue; } if (jsonProperty.IsJsonObject) { jsonProperty.PropertyInfo.SetValue(instance, element.Value, null); continue; } if (jsonProperty.ObjectType == JsonObjectType.Runtime) { continue; } if (jsonProperty.ObjectType == JsonObjectType.Dictionary) { if (element.Value is JsonDictionaryObject) { var value = GetSerializer(jsonProperty.PropertyInfo.PropertyType).InternalDeserialize(element.Value); jsonProperty.PropertyInfo.SetValue(instance, value, null); } else if (element.Value is JsonValueObject && JsonEncoder.IsNullValue(element.Value)) { jsonProperty.PropertyInfo.SetValue(instance, null, null); } else { throw new Errors.JsonSerializeFailedException(element.Key, ".net runtime type does not match json type."); } } else if (jsonProperty.ObjectType == JsonObjectType.Collection) { if (element.Value is JsonCollectionObject) { var collectionObject = element.Value as JsonCollectionObject; jsonProperty.PropertyInfo.SetValue(instance, DeserializeJsonCollectionObject(collectionObject, jsonProperty.PropertyInfo.PropertyType), null); } else if (element.Value is JsonValueObject && JsonEncoder.IsNullValue(element.Value)) { jsonProperty.PropertyInfo.SetValue(instance, null, null); } else { throw new Errors.JsonSerializeFailedException(element.Key, ".net runtime type does not match json type."); } } else if (jsonProperty.ObjectType == JsonObjectType.Value && element.Value is JsonValueObject) { var value = DeserializeJsonPlainValueObject(element.Value as JsonValueObject, jsonProperty.PropertyInfo.PropertyType); jsonProperty.PropertyInfo.SetValue(instance, value, null); } else { throw new Errors.JsonSerializeFailedException(element.Key, ".net runtime type does not match json type."); } } return(instance); }