-Removed obsolete JsonConverter.GetSchema

-Removed obsolete OnDeserialized, OnDeserializing, OnSerialized, OnSerializing, OnError from JsonContract
-Removed obsolete JsonDictionaryContract.PropertyNameResolver
-Removed obsolete ConstructorParameters, OverrideConstructor, ParametrizedConstructor from JsonObjectContract
This commit is contained in:
James Newton-King
2017-01-22 22:28:22 +13:00
parent e1ec6e9a18
commit 07b513cb83
8 changed files with 10 additions and 184 deletions
@@ -442,15 +442,10 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.IsNull(contract.DefaultCreator);
Assert.IsNotNull(contract.ParameterizedCreator);
#pragma warning disable 618
Assert.AreEqual(contract.ParametrizedConstructor, typeof(PublicParameterizedConstructorWithPropertyNameConflictWithAttribute).GetConstructor(new[] { typeof(string) }));
#pragma warning restore 618
Assert.AreEqual(1, contract.CreatorParameters.Count);
Assert.AreEqual("name", contract.CreatorParameters[0].PropertyName);
#pragma warning disable 618
contract.ParametrizedConstructor = null;
#pragma warning restore 618
contract.ParameterizedCreator = null;
Assert.IsNull(contract.ParameterizedCreator);
}
@@ -462,16 +457,11 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.IsNull(contract.DefaultCreator);
Assert.IsNotNull(contract.OverrideCreator);
#pragma warning disable 618
Assert.AreEqual(contract.OverrideConstructor, typeof(MultipleParametrizedConstructorsJsonConstructor).GetConstructor(new[] { typeof(string), typeof(int) }));
#pragma warning restore 618
Assert.AreEqual(2, contract.CreatorParameters.Count);
Assert.AreEqual("Value", contract.CreatorParameters[0].PropertyName);
Assert.AreEqual("Age", contract.CreatorParameters[1].PropertyName);
#pragma warning disable 618
contract.OverrideConstructor = null;
#pragma warning restore 618
contract.OverrideCreator = null;
Assert.IsNull(contract.OverrideCreator);
}
@@ -488,9 +478,7 @@ namespace Newtonsoft.Json.Tests.Serialization
ensureCustomCreatorCalled = true;
return new MultipleParametrizedConstructorsJsonConstructor((string)args[0], (int)args[1]);
};
#pragma warning disable 618
Assert.IsNull(contract.OverrideConstructor);
#pragma warning restore 618
Assert.IsNotNull(contract.OverrideCreator);
var o = JsonConvert.DeserializeObject<MultipleParametrizedConstructorsJsonConstructor>("{Value:'value!', Age:1}", new JsonSerializerSettings
{
@@ -309,10 +309,7 @@ namespace Newtonsoft.Json.Tests.Serialization
// Verify contract is properly finding our callback
var resolver = new DefaultContractResolver().ResolveContract(typeof(FooEvent));
#pragma warning disable 612,618
Debug.Assert(resolver.OnError != null);
Debug.Assert(resolver.OnError == typeof(FooEvent).GetMethod("OnError", BindingFlags.Instance | BindingFlags.NonPublic));
#pragma warning restore 612,618
Assert.AreEqual(resolver.OnErrorCallbacks.Count, 1);
var serializer = JsonSerializer.Create(new JsonSerializerSettings
{
@@ -325,7 +322,7 @@ namespace Newtonsoft.Json.Tests.Serialization
var foo = serializer.Deserialize<FooEvent>(new JsonTextReader(new StringReader("{ Id: 25 }")));
// When fixed, this would pass.
Debug.Assert(foo.Identifier == 25);
Assert.AreEqual(25, foo.Identifier);
}
#endif
-15
View File
@@ -63,21 +63,6 @@ namespace Newtonsoft.Json
/// </returns>
public abstract bool CanConvert(Type objectType);
/// <summary>
/// <para>
/// Gets the <see cref="JsonSchema"/> of the JSON produced by the <see cref="JsonConverter"/>.
/// </para>
/// <note type="caution">
/// JSON Schema validation has been moved to its own package. See <see href="http://www.newtonsoft.com/jsonschema">http://www.newtonsoft.com/jsonschema</see> for more details.
/// </note>
/// </summary>
/// <returns>The <see cref="JsonSchema"/> of the JSON produced by the <see cref="JsonConverter"/>.</returns>
[Obsolete("JSON Schema validation has been moved to its own package. It is strongly recommended that you do not override GetSchema() in your own converter. It is not used by Json.NET and will be removed at some point in the future. Converter's that override GetSchema() will stop working when it is removed.")]
public virtual JsonSchema GetSchema()
{
return null;
}
/// <summary>
/// Gets a value indicating whether this <see cref="JsonConverter"/> can read JSON.
/// </summary>
@@ -260,15 +260,7 @@ namespace Newtonsoft.Json.Schema
}
JsonContract contract = ContractResolver.ResolveContract(type);
JsonConverter converter;
if ((converter = contract.Converter) != null || (converter = contract.InternalConverter) != null)
{
JsonSchema converterSchema = converter.GetSchema();
if (converterSchema != null)
{
return converterSchema;
}
}
JsonConverter converter = contract.Converter ?? contract.InternalConverter;
Push(new TypeSchema(type, new JsonSchema()));
@@ -425,9 +425,7 @@ namespace Newtonsoft.Json.Serialization
// check if a JsonConstructorAttribute has been defined and use that
if (overrideConstructor != null)
{
#pragma warning disable 618
contract.OverrideConstructor = overrideConstructor;
#pragma warning restore 618
contract.OverrideCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateParameterizedConstructor(overrideConstructor);
contract.CreatorParameters.AddRange(CreateConstructorParameters(overrideConstructor, contract.Properties));
}
else if (contract.MemberSerialization == MemberSerialization.Fields)
@@ -446,9 +444,7 @@ namespace Newtonsoft.Json.Serialization
ConstructorInfo constructor = GetParameterizedConstructor(contract.NonNullableUnderlyingType);
if (constructor != null)
{
#pragma warning disable 618
contract.ParametrizedConstructor = constructor;
#pragma warning restore 618
contract.ParameterizedCreator = JsonTypeReflector.ReflectionDelegateFactory.CreateParameterizedConstructor(constructor);
contract.CreatorParameters.AddRange(CreateConstructorParameters(constructor, contract.Properties));
}
}
@@ -220,81 +220,6 @@ namespace Newtonsoft.Json.Serialization
}
}
/// <summary>
/// Gets or sets the method called immediately after deserialization of the object.
/// </summary>
/// <value>The method called immediately after deserialization of the object.</value>
[Obsolete("This property is obsolete and has been replaced by the OnDeserializedCallbacks collection.")]
public MethodInfo OnDeserialized
{
get { return (OnDeserializedCallbacks.Count > 0) ? OnDeserializedCallbacks[0].Method() : null; }
set
{
OnDeserializedCallbacks.Clear();
OnDeserializedCallbacks.Add(CreateSerializationCallback(value));
}
}
/// <summary>
/// Gets or sets the method called during deserialization of the object.
/// </summary>
/// <value>The method called during deserialization of the object.</value>
[Obsolete("This property is obsolete and has been replaced by the OnDeserializingCallbacks collection.")]
public MethodInfo OnDeserializing
{
get { return (OnDeserializingCallbacks.Count > 0) ? OnDeserializingCallbacks[0].Method() : null; }
set
{
OnDeserializingCallbacks.Clear();
OnDeserializingCallbacks.Add(CreateSerializationCallback(value));
}
}
/// <summary>
/// Gets or sets the method called after serialization of the object graph.
/// </summary>
/// <value>The method called after serialization of the object graph.</value>
[Obsolete("This property is obsolete and has been replaced by the OnSerializedCallbacks collection.")]
public MethodInfo OnSerialized
{
get { return (OnSerializedCallbacks.Count > 0) ? OnSerializedCallbacks[0].Method() : null; }
set
{
OnSerializedCallbacks.Clear();
OnSerializedCallbacks.Add(CreateSerializationCallback(value));
}
}
/// <summary>
/// Gets or sets the method called before serialization of the object.
/// </summary>
/// <value>The method called before serialization of the object.</value>
[Obsolete("This property is obsolete and has been replaced by the OnSerializingCallbacks collection.")]
public MethodInfo OnSerializing
{
get { return (OnSerializingCallbacks.Count > 0) ? OnSerializingCallbacks[0].Method() : null; }
set
{
OnSerializingCallbacks.Clear();
OnSerializingCallbacks.Add(CreateSerializationCallback(value));
}
}
/// <summary>
/// Gets or sets the method called when an error is thrown during the serialization of the object.
/// </summary>
/// <value>The method called when an error is thrown during the serialization of the object.</value>
[Obsolete("This property is obsolete and has been replaced by the OnErrorCallbacks collection.")]
public MethodInfo OnError
{
get { return (OnErrorCallbacks.Count > 0) ? OnErrorCallbacks[0].Method() : null; }
set
{
OnErrorCallbacks.Clear();
OnErrorCallbacks.Add(CreateSerializationErrorCallback(value));
}
}
/// <summary>
/// Gets or sets the default creator method used to create the object.
/// </summary>
@@ -41,17 +41,6 @@ namespace Newtonsoft.Json.Serialization
/// </summary>
public class JsonDictionaryContract : JsonContainerContract
{
/// <summary>
/// Gets or sets the property name resolver.
/// </summary>
/// <value>The property name resolver.</value>
[Obsolete("PropertyNameResolver is obsolete. Use DictionaryKeyResolver instead.")]
public Func<string, string> PropertyNameResolver
{
get { return DictionaryKeyResolver; }
set { DictionaryKeyResolver = value; }
}
/// <summary>
/// Gets or sets the dictionary key resolver.
/// </summary>
@@ -58,15 +58,6 @@ namespace Newtonsoft.Json.Serialization
/// <value>The object's properties.</value>
public JsonPropertyCollection Properties { get; private set; }
/// <summary>
/// Gets the constructor parameters required for any non-default constructor.
/// </summary>
[Obsolete("ConstructorParameters is obsolete. Use CreatorParameters instead.")]
public JsonPropertyCollection ConstructorParameters
{
get { return CreatorParameters; }
}
/// <summary>
/// Gets a collection of <see cref="JsonProperty"/> instances that define the parameters used with <see cref="JsonObjectContract.OverrideCreator"/>.
/// </summary>
@@ -83,38 +74,6 @@ namespace Newtonsoft.Json.Serialization
}
}
/// <summary>
/// Gets or sets the override constructor used to create the object.
/// This is set when a constructor is marked up using
/// <see cref="JsonConstructorAttribute"/>.
/// </summary>
/// <value>The override constructor.</value>
[Obsolete("OverrideConstructor is obsolete. Use OverrideCreator instead.")]
public ConstructorInfo OverrideConstructor
{
get { return _overrideConstructor; }
set
{
_overrideConstructor = value;
_overrideCreator = (value != null) ? JsonTypeReflector.ReflectionDelegateFactory.CreateParameterizedConstructor(value) : null;
}
}
/// <summary>
/// Gets or sets the parametrized constructor used to create the object.
/// </summary>
/// <value>The parametrized constructor.</value>
[Obsolete("ParametrizedConstructor is obsolete. Use OverrideCreator instead.")]
public ConstructorInfo ParametrizedConstructor
{
get { return _parametrizedConstructor; }
set
{
_parametrizedConstructor = value;
_parameterizedCreator = (value != null) ? JsonTypeReflector.ReflectionDelegateFactory.CreateParameterizedConstructor(value) : null;
}
}
/// <summary>
/// Gets or sets the function used to create the object. When set this function will override <see cref="JsonContract.DefaultCreator"/>.
/// This function is called with a collection of arguments which are defined by the <see cref="JsonObjectContract.CreatorParameters"/> collection.
@@ -123,16 +82,13 @@ namespace Newtonsoft.Json.Serialization
public ObjectConstructor<object> OverrideCreator
{
get { return _overrideCreator; }
set
{
_overrideCreator = value;
_overrideConstructor = null;
}
set { _overrideCreator = value; }
}
internal ObjectConstructor<object> ParameterizedCreator
{
get { return _parameterizedCreator; }
set { _parameterizedCreator = value; }
}
/// <summary>
@@ -166,8 +122,6 @@ namespace Newtonsoft.Json.Serialization
internal bool ExtensionDataIsJToken;
private bool? _hasRequiredOrDefaultValueProperties;
private ConstructorInfo _parametrizedConstructor;
private ConstructorInfo _overrideConstructor;
private ObjectConstructor<object> _overrideCreator;
private ObjectConstructor<object> _parameterizedCreator;
private JsonPropertyCollection _creatorParameters;