Fix blank extension data values with required properties and ctor (#1850)
This commit is contained in:
@@ -35,6 +35,7 @@ using System.Xml;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
#if HAVE_XLINQ
|
||||
using System.Xml.Linq;
|
||||
|
||||
@@ -522,6 +523,7 @@ namespace Newtonsoft.Json
|
||||
/// </summary>
|
||||
/// <param name="value">The object to serialize.</param>
|
||||
/// <returns>A JSON string representation of the object.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static string SerializeObject(object value)
|
||||
{
|
||||
return SerializeObject(value, null, (JsonSerializerSettings)null);
|
||||
@@ -535,6 +537,7 @@ namespace Newtonsoft.Json
|
||||
/// <returns>
|
||||
/// A JSON string representation of the object.
|
||||
/// </returns>
|
||||
[DebuggerStepThrough]
|
||||
public static string SerializeObject(object value, Formatting formatting)
|
||||
{
|
||||
return SerializeObject(value, formatting, (JsonSerializerSettings)null);
|
||||
@@ -546,6 +549,7 @@ namespace Newtonsoft.Json
|
||||
/// <param name="value">The object to serialize.</param>
|
||||
/// <param name="converters">A collection of converters used while serializing.</param>
|
||||
/// <returns>A JSON string representation of the object.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static string SerializeObject(object value, params JsonConverter[] converters)
|
||||
{
|
||||
JsonSerializerSettings settings = (converters != null && converters.Length > 0)
|
||||
@@ -562,6 +566,7 @@ namespace Newtonsoft.Json
|
||||
/// <param name="formatting">Indicates how the output should be formatted.</param>
|
||||
/// <param name="converters">A collection of converters used while serializing.</param>
|
||||
/// <returns>A JSON string representation of the object.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static string SerializeObject(object value, Formatting formatting, params JsonConverter[] converters)
|
||||
{
|
||||
JsonSerializerSettings settings = (converters != null && converters.Length > 0)
|
||||
@@ -580,6 +585,7 @@ namespace Newtonsoft.Json
|
||||
/// <returns>
|
||||
/// A JSON string representation of the object.
|
||||
/// </returns>
|
||||
[DebuggerStepThrough]
|
||||
public static string SerializeObject(object value, JsonSerializerSettings settings)
|
||||
{
|
||||
return SerializeObject(value, null, settings);
|
||||
@@ -599,6 +605,7 @@ namespace Newtonsoft.Json
|
||||
/// <returns>
|
||||
/// A JSON string representation of the object.
|
||||
/// </returns>
|
||||
[DebuggerStepThrough]
|
||||
public static string SerializeObject(object value, Type type, JsonSerializerSettings settings)
|
||||
{
|
||||
JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(settings);
|
||||
@@ -616,6 +623,7 @@ namespace Newtonsoft.Json
|
||||
/// <returns>
|
||||
/// A JSON string representation of the object.
|
||||
/// </returns>
|
||||
[DebuggerStepThrough]
|
||||
public static string SerializeObject(object value, Formatting formatting, JsonSerializerSettings settings)
|
||||
{
|
||||
return SerializeObject(value, null, formatting, settings);
|
||||
@@ -636,6 +644,7 @@ namespace Newtonsoft.Json
|
||||
/// <returns>
|
||||
/// A JSON string representation of the object.
|
||||
/// </returns>
|
||||
[DebuggerStepThrough]
|
||||
public static string SerializeObject(object value, Type type, Formatting formatting, JsonSerializerSettings settings)
|
||||
{
|
||||
JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(settings);
|
||||
@@ -665,6 +674,7 @@ namespace Newtonsoft.Json
|
||||
/// </summary>
|
||||
/// <param name="value">The JSON to deserialize.</param>
|
||||
/// <returns>The deserialized object from the JSON string.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static object DeserializeObject(string value)
|
||||
{
|
||||
return DeserializeObject(value, null, (JsonSerializerSettings)null);
|
||||
@@ -679,6 +689,7 @@ namespace Newtonsoft.Json
|
||||
/// If this is <c>null</c>, default serialization settings will be used.
|
||||
/// </param>
|
||||
/// <returns>The deserialized object from the JSON string.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static object DeserializeObject(string value, JsonSerializerSettings settings)
|
||||
{
|
||||
return DeserializeObject(value, null, settings);
|
||||
@@ -690,6 +701,7 @@ namespace Newtonsoft.Json
|
||||
/// <param name="value">The JSON to deserialize.</param>
|
||||
/// <param name="type">The <see cref="Type"/> of object being deserialized.</param>
|
||||
/// <returns>The deserialized object from the JSON string.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static object DeserializeObject(string value, Type type)
|
||||
{
|
||||
return DeserializeObject(value, type, (JsonSerializerSettings)null);
|
||||
@@ -701,6 +713,7 @@ namespace Newtonsoft.Json
|
||||
/// <typeparam name="T">The type of the object to deserialize to.</typeparam>
|
||||
/// <param name="value">The JSON to deserialize.</param>
|
||||
/// <returns>The deserialized object from the JSON string.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static T DeserializeObject<T>(string value)
|
||||
{
|
||||
return DeserializeObject<T>(value, (JsonSerializerSettings)null);
|
||||
@@ -717,6 +730,7 @@ namespace Newtonsoft.Json
|
||||
/// <param name="value">The JSON to deserialize.</param>
|
||||
/// <param name="anonymousTypeObject">The anonymous type object.</param>
|
||||
/// <returns>The deserialized anonymous type from the JSON string.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static T DeserializeAnonymousType<T>(string value, T anonymousTypeObject)
|
||||
{
|
||||
return DeserializeObject<T>(value);
|
||||
@@ -737,6 +751,7 @@ namespace Newtonsoft.Json
|
||||
/// If this is <c>null</c>, default serialization settings will be used.
|
||||
/// </param>
|
||||
/// <returns>The deserialized anonymous type from the JSON string.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static T DeserializeAnonymousType<T>(string value, T anonymousTypeObject, JsonSerializerSettings settings)
|
||||
{
|
||||
return DeserializeObject<T>(value, settings);
|
||||
@@ -749,6 +764,7 @@ namespace Newtonsoft.Json
|
||||
/// <param name="value">The JSON to deserialize.</param>
|
||||
/// <param name="converters">Converters to use while deserializing.</param>
|
||||
/// <returns>The deserialized object from the JSON string.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static T DeserializeObject<T>(string value, params JsonConverter[] converters)
|
||||
{
|
||||
return (T)DeserializeObject(value, typeof(T), converters);
|
||||
@@ -764,6 +780,7 @@ namespace Newtonsoft.Json
|
||||
/// If this is <c>null</c>, default serialization settings will be used.
|
||||
/// </param>
|
||||
/// <returns>The deserialized object from the JSON string.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static T DeserializeObject<T>(string value, JsonSerializerSettings settings)
|
||||
{
|
||||
return (T)DeserializeObject(value, typeof(T), settings);
|
||||
@@ -776,6 +793,7 @@ namespace Newtonsoft.Json
|
||||
/// <param name="type">The type of the object to deserialize.</param>
|
||||
/// <param name="converters">Converters to use while deserializing.</param>
|
||||
/// <returns>The deserialized object from the JSON string.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public static object DeserializeObject(string value, Type type, params JsonConverter[] converters)
|
||||
{
|
||||
JsonSerializerSettings settings = (converters != null && converters.Length > 0)
|
||||
@@ -820,6 +838,7 @@ namespace Newtonsoft.Json
|
||||
/// </summary>
|
||||
/// <param name="value">The JSON to populate values from.</param>
|
||||
/// <param name="target">The target object to populate values onto.</param>
|
||||
[DebuggerStepThrough]
|
||||
public static void PopulateObject(string value, object target)
|
||||
{
|
||||
PopulateObject(value, target, null);
|
||||
|
||||
@@ -790,6 +790,7 @@ namespace Newtonsoft.Json
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="TextReader"/> that contains the JSON structure to read values from.</param>
|
||||
/// <param name="target">The target object to populate values onto.</param>
|
||||
[DebuggerStepThrough]
|
||||
public void Populate(TextReader reader, object target)
|
||||
{
|
||||
Populate(new JsonTextReader(reader), target);
|
||||
@@ -800,6 +801,7 @@ namespace Newtonsoft.Json
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="JsonReader"/> that contains the JSON structure to read values from.</param>
|
||||
/// <param name="target">The target object to populate values onto.</param>
|
||||
[DebuggerStepThrough]
|
||||
public void Populate(JsonReader reader, object target)
|
||||
{
|
||||
PopulateInternal(reader, target);
|
||||
@@ -839,6 +841,7 @@ namespace Newtonsoft.Json
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="JsonReader"/> that contains the JSON structure to deserialize.</param>
|
||||
/// <returns>The <see cref="Object"/> being deserialized.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public object Deserialize(JsonReader reader)
|
||||
{
|
||||
return Deserialize(reader, null);
|
||||
@@ -851,6 +854,7 @@ namespace Newtonsoft.Json
|
||||
/// <param name="reader">The <see cref="TextReader"/> containing the object.</param>
|
||||
/// <param name="objectType">The <see cref="Type"/> of object being deserialized.</param>
|
||||
/// <returns>The instance of <paramref name="objectType"/> being deserialized.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public object Deserialize(TextReader reader, Type objectType)
|
||||
{
|
||||
return Deserialize(new JsonTextReader(reader), objectType);
|
||||
@@ -863,6 +867,7 @@ namespace Newtonsoft.Json
|
||||
/// <param name="reader">The <see cref="JsonReader"/> containing the object.</param>
|
||||
/// <typeparam name="T">The type of the object to deserialize.</typeparam>
|
||||
/// <returns>The instance of <typeparamref name="T"/> being deserialized.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public T Deserialize<T>(JsonReader reader)
|
||||
{
|
||||
return (T)Deserialize(reader, typeof(T));
|
||||
@@ -875,6 +880,7 @@ namespace Newtonsoft.Json
|
||||
/// <param name="reader">The <see cref="JsonReader"/> containing the object.</param>
|
||||
/// <param name="objectType">The <see cref="Type"/> of object being deserialized.</param>
|
||||
/// <returns>The instance of <paramref name="objectType"/> being deserialized.</returns>
|
||||
[DebuggerStepThrough]
|
||||
public object Deserialize(JsonReader reader, Type objectType)
|
||||
{
|
||||
return DeserializeInternal(reader, objectType);
|
||||
|
||||
@@ -1906,14 +1906,17 @@ namespace Newtonsoft.Json.Serialization
|
||||
{
|
||||
foreach (JsonProperty property in contract.Properties)
|
||||
{
|
||||
if (propertyContexts.All(p => p.Property != property))
|
||||
if (!property.Ignored)
|
||||
{
|
||||
propertyContexts.Add(new CreatorPropertyContext
|
||||
if (propertyContexts.All(p => p.Property != property))
|
||||
{
|
||||
Property = property,
|
||||
Name = property.PropertyName,
|
||||
Presence = PropertyPresence.None
|
||||
});
|
||||
propertyContexts.Add(new CreatorPropertyContext
|
||||
{
|
||||
Property = property,
|
||||
Name = property.PropertyName,
|
||||
Presence = PropertyPresence.None
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2076,7 +2079,7 @@ namespace Newtonsoft.Json.Serialization
|
||||
{
|
||||
foreach (CreatorPropertyContext propertyValue in propertyContexts)
|
||||
{
|
||||
if (!propertyValue.Used)
|
||||
if (!propertyValue.Used && propertyValue.Presence != PropertyPresence.None)
|
||||
{
|
||||
contract.ExtensionDataSetter(createdObject, propertyValue.Name, propertyValue.Value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user