private void WriteMemberInfoProperty(JsonWriter writer, object memberValue, JsonProperty property, JsonContract contract) { string propertyName = property.PropertyName; object defaultValue = property.DefaultValue; if (property.NullValueHandling.GetValueOrDefault(Serializer.NullValueHandling) == NullValueHandling.Ignore && memberValue == null) { return; } if (HasFlag(property.DefaultValueHandling.GetValueOrDefault(Serializer.DefaultValueHandling), DefaultValueHandling.Ignore) && MiscellaneousUtils.ValueEquals(memberValue, defaultValue)) { return; } if (ShouldWriteReference(memberValue, property, contract)) { writer.WritePropertyName(propertyName); WriteReference(writer, memberValue); return; } if (!CheckForCircularReference(memberValue, property.ReferenceLoopHandling, contract)) { return; } if (memberValue == null && property.Required == Required.Always) { throw new JsonSerializationException("Cannot write a null value for property '{0}'. Property requires a value.".FormatWith(CultureInfo.InvariantCulture, property.PropertyName)); } // Aditi Start : Added to resolve Items and Item issue if (string.Equals(property.PropertyName.ToUpper(), _anyIntuitObjects) && string.Equals(property.PropertyType.Name.ToUpper(), _objectArray)) { if (memberValue != null) { string memberName = memberValue.GetType().Name; if (memberName.Contains("[]")) { memberName = memberName.Substring(0, memberName.IndexOf('[')); } propertyName = memberName; } } if (string.Equals(property.PropertyName.ToUpper(), _anyIntuitObject) && string.Equals(property.PropertyType.Name.ToUpper(), _object)) { if (memberValue != null) { propertyName = memberValue.GetType().Name; } } // Aditi End writer.WritePropertyName(propertyName); SerializeValue(writer, memberValue, contract, property, null); }
private bool ShouldWriteDynamicProperty(object memberValue) { if (Serializer._nullValueHandling == NullValueHandling.Ignore && memberValue == null) { return(false); } if (HasFlag(Serializer._defaultValueHandling, DefaultValueHandling.Ignore) && (memberValue == null || MiscellaneousUtils.ValueEquals(memberValue, ReflectionUtils.GetDefaultValue(memberValue.GetType())))) { return(false); } return(true); }
private bool ShouldWriteProperty(object memberValue, JsonObjectContract containerContract, JsonProperty property) { if (memberValue == null && ResolvedNullValueHandling(containerContract, property) == NullValueHandling.Ignore) { return(false); } if (HasFlag(property.DefaultValueHandling.GetValueOrDefault(Serializer._defaultValueHandling), DefaultValueHandling.Ignore) && MiscellaneousUtils.ValueEquals(memberValue, property.GetResolvedDefaultValue())) { return(false); } return(true); }
private bool ShouldWriteProperty(object memberValue, JsonProperty property) { if (property.NullValueHandling.GetValueOrDefault(Serializer.NullValueHandling) == NullValueHandling.Ignore && memberValue == null) { return(false); } if (HasFlag(property.DefaultValueHandling.GetValueOrDefault(Serializer.DefaultValueHandling), DefaultValueHandling.Ignore) && MiscellaneousUtils.ValueEquals(memberValue, property.DefaultValue)) { return(false); } return(true); }
private bool ShouldWriteProperty(object memberValue, JsonProperty property) { if (property.NullValueHandling.GetValueOrDefault(Serializer._nullValueHandling) == NullValueHandling.Ignore && (memberValue == null || string.IsNullOrEmpty(memberValue.ToString()))) { return(false); } if (HasFlag(property.DefaultValueHandling.GetValueOrDefault(Serializer._defaultValueHandling), DefaultValueHandling.Ignore) && MiscellaneousUtils.ValueEquals(memberValue, property.GetResolvedDefaultValue())) { return(false); } return(true); }
private void WriteMemberInfoProperty(JsonWriter writer, object memberValue, JsonProperty property, JsonContract contract, bool writePropertyName = true) { string propertyName = property.PropertyName; object defaultValue = property.DefaultValue; if (property.NullValueHandling.GetValueOrDefault(Serializer.NullValueHandling) == NullValueHandling.Ignore && memberValue == null) { return; } if (HasFlag(property.DefaultValueHandling.GetValueOrDefault(Serializer.DefaultValueHandling), DefaultValueHandling.Ignore) && MiscellaneousUtils.ValueEquals(memberValue, defaultValue)) { return; } if (ShouldWriteReference(memberValue, property, contract)) { writer.WritePropertyName(propertyName, writePropertyName); WriteReference(writer, memberValue); return; } if (!CheckForCircularReference(memberValue, property.ReferenceLoopHandling, contract)) { return; } if (memberValue == null && property.Required == Required.Always) { throw new JsonSerializationException("Cannot write a null value for property '{0}'. Property requires a value.".FormatWith(CultureInfo.InvariantCulture, property.PropertyName)); } writer.WritePropertyName(propertyName, writePropertyName); SerializeValue(writer, memberValue, contract, property, null, writePropertyName); }
private bool ShouldSetPropertyValue(JsonProperty property, object value) { if (property.NullValueHandling.GetValueOrDefault(Serializer.NullValueHandling) == NullValueHandling.Ignore && value == null) { return(false); } if (property.DefaultValueHandling.GetValueOrDefault(Serializer.DefaultValueHandling) == DefaultValueHandling.Ignore && MiscellaneousUtils.ValueEquals(value, property.DefaultValue)) { return(false); } if (!property.Writable) { return(false); } return(true); }
private bool ShouldWriteDynamicProperty(object memberValue) { return((this.Serializer._nullValueHandling != NullValueHandling.Ignore || memberValue != null) && (!this.HasFlag(this.Serializer._defaultValueHandling, DefaultValueHandling.Ignore) || (memberValue != null && !MiscellaneousUtils.ValueEquals(memberValue, ReflectionUtils.GetDefaultValue(memberValue.GetType()))))); }
private bool ShouldWriteProperty(object memberValue, JsonProperty property) { return((property.NullValueHandling.GetValueOrDefault(this.Serializer._nullValueHandling) != NullValueHandling.Ignore || memberValue != null) && (!this.HasFlag(property.DefaultValueHandling.GetValueOrDefault(this.Serializer._defaultValueHandling), DefaultValueHandling.Ignore) || !MiscellaneousUtils.ValueEquals(memberValue, property.GetResolvedDefaultValue()))); }
private void SetPropertyValue(JsonProperty property, JsonReader reader, object target) { if (property.Ignored) { reader.Skip(); return; } object obj = null; bool flag = false; bool gottenCurrentValue = false; ObjectCreationHandling valueOrDefault = property.ObjectCreationHandling.GetValueOrDefault(base.Serializer.ObjectCreationHandling); if ((valueOrDefault == ObjectCreationHandling.Auto || valueOrDefault == ObjectCreationHandling.Reuse) && (reader.TokenType == JsonToken.StartArray || reader.TokenType == JsonToken.StartObject) && property.Readable) { obj = property.ValueProvider.GetValue(target); gottenCurrentValue = true; flag = obj != null && !property.PropertyType.IsArray && !ReflectionUtils.InheritsGenericDefinition(property.PropertyType, typeof(ReadOnlyCollection <>)) && !property.PropertyType.IsValueType; } if (!property.Writable && !flag) { reader.Skip(); return; } if (property.NullValueHandling.GetValueOrDefault(base.Serializer.NullValueHandling) == NullValueHandling.Ignore && reader.TokenType == JsonToken.Null) { reader.Skip(); return; } if (HasFlag(property.DefaultValueHandling.GetValueOrDefault(base.Serializer.DefaultValueHandling), DefaultValueHandling.Ignore) && JsonReader.IsPrimitiveToken(reader.TokenType) && MiscellaneousUtils.ValueEquals(reader.Value, property.DefaultValue)) { reader.Skip(); return; } object currentValue = (flag ? obj : null); object obj2 = CreateValueProperty(reader, property, target, gottenCurrentValue, currentValue); if ((!flag || obj2 != obj) && ShouldSetPropertyValue(property, obj2)) { property.ValueProvider.SetValue(target, obj2); if (property.SetIsSpecified != null) { property.SetIsSpecified(target, true); } } }