From 07b513cb83d70116b324248c951ffca075a7a97a Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sun, 22 Jan 2017 22:28:22 +1300 Subject: [PATCH] -Removed obsolete JsonConverter.GetSchema -Removed obsolete OnDeserialized, OnDeserializing, OnSerialized, OnSerializing, OnError from JsonContract -Removed obsolete JsonDictionaryContract.PropertyNameResolver -Removed obsolete ConstructorParameters, OverrideConstructor, ParametrizedConstructor from JsonObjectContract --- .../Serialization/ContractResolverTests.cs | 18 +---- .../SerializationEventAttributeTests.cs | 7 +- Src/Newtonsoft.Json/JsonConverter.cs | 15 ---- .../Schema/JsonSchemaGenerator.cs | 10 +-- .../Serialization/DefaultContractResolver.cs | 8 +- .../Serialization/JsonContract.cs | 75 ------------------- .../Serialization/JsonDictionaryContract.cs | 11 --- .../Serialization/JsonObjectContract.cs | 50 +------------ 8 files changed, 10 insertions(+), 184 deletions(-) diff --git a/Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs index 249b8775..869984d9 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs @@ -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("{Value:'value!', Age:1}", new JsonSerializerSettings { diff --git a/Src/Newtonsoft.Json.Tests/Serialization/SerializationEventAttributeTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/SerializationEventAttributeTests.cs index 23ceaa9c..e539829b 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/SerializationEventAttributeTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/SerializationEventAttributeTests.cs @@ -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(new JsonTextReader(new StringReader("{ Id: 25 }"))); // When fixed, this would pass. - Debug.Assert(foo.Identifier == 25); + Assert.AreEqual(25, foo.Identifier); } #endif diff --git a/Src/Newtonsoft.Json/JsonConverter.cs b/Src/Newtonsoft.Json/JsonConverter.cs index 45895401..3f04f620 100644 --- a/Src/Newtonsoft.Json/JsonConverter.cs +++ b/Src/Newtonsoft.Json/JsonConverter.cs @@ -63,21 +63,6 @@ namespace Newtonsoft.Json /// public abstract bool CanConvert(Type objectType); - /// - /// - /// Gets the of the JSON produced by the . - /// - /// - /// JSON Schema validation has been moved to its own package. See http://www.newtonsoft.com/jsonschema for more details. - /// - /// - /// The of the JSON produced by the . - [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; - } - /// /// Gets a value indicating whether this can read JSON. /// diff --git a/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs b/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs index 9a0b7574..0bbcc3b9 100644 --- a/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs +++ b/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs @@ -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())); diff --git a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs index 0a22af69..8d26e39f 100644 --- a/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs +++ b/Src/Newtonsoft.Json/Serialization/DefaultContractResolver.cs @@ -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)); } } diff --git a/Src/Newtonsoft.Json/Serialization/JsonContract.cs b/Src/Newtonsoft.Json/Serialization/JsonContract.cs index 4614f369..8dbc3df8 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonContract.cs @@ -220,81 +220,6 @@ namespace Newtonsoft.Json.Serialization } } - /// - /// Gets or sets the method called immediately after deserialization of the object. - /// - /// The method called immediately after deserialization of the object. - [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)); - } - } - - /// - /// Gets or sets the method called during deserialization of the object. - /// - /// The method called during deserialization of the object. - [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)); - } - } - - /// - /// Gets or sets the method called after serialization of the object graph. - /// - /// The method called after serialization of the object graph. - [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)); - } - } - - /// - /// Gets or sets the method called before serialization of the object. - /// - /// The method called before serialization of the object. - [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)); - } - } - - /// - /// Gets or sets the method called when an error is thrown during the serialization of the object. - /// - /// The method called when an error is thrown during the serialization of the object. - [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)); - } - } - /// /// Gets or sets the default creator method used to create the object. /// diff --git a/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs b/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs index e90d965b..5236a9a6 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonDictionaryContract.cs @@ -41,17 +41,6 @@ namespace Newtonsoft.Json.Serialization /// public class JsonDictionaryContract : JsonContainerContract { - /// - /// Gets or sets the property name resolver. - /// - /// The property name resolver. - [Obsolete("PropertyNameResolver is obsolete. Use DictionaryKeyResolver instead.")] - public Func PropertyNameResolver - { - get { return DictionaryKeyResolver; } - set { DictionaryKeyResolver = value; } - } - /// /// Gets or sets the dictionary key resolver. /// diff --git a/Src/Newtonsoft.Json/Serialization/JsonObjectContract.cs b/Src/Newtonsoft.Json/Serialization/JsonObjectContract.cs index 931eb578..e7aecc9f 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonObjectContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonObjectContract.cs @@ -58,15 +58,6 @@ namespace Newtonsoft.Json.Serialization /// The object's properties. public JsonPropertyCollection Properties { get; private set; } - /// - /// Gets the constructor parameters required for any non-default constructor. - /// - [Obsolete("ConstructorParameters is obsolete. Use CreatorParameters instead.")] - public JsonPropertyCollection ConstructorParameters - { - get { return CreatorParameters; } - } - /// /// Gets a collection of instances that define the parameters used with . /// @@ -83,38 +74,6 @@ namespace Newtonsoft.Json.Serialization } } - /// - /// Gets or sets the override constructor used to create the object. - /// This is set when a constructor is marked up using - /// . - /// - /// The override constructor. - [Obsolete("OverrideConstructor is obsolete. Use OverrideCreator instead.")] - public ConstructorInfo OverrideConstructor - { - get { return _overrideConstructor; } - set - { - _overrideConstructor = value; - _overrideCreator = (value != null) ? JsonTypeReflector.ReflectionDelegateFactory.CreateParameterizedConstructor(value) : null; - } - } - - /// - /// Gets or sets the parametrized constructor used to create the object. - /// - /// The parametrized constructor. - [Obsolete("ParametrizedConstructor is obsolete. Use OverrideCreator instead.")] - public ConstructorInfo ParametrizedConstructor - { - get { return _parametrizedConstructor; } - set - { - _parametrizedConstructor = value; - _parameterizedCreator = (value != null) ? JsonTypeReflector.ReflectionDelegateFactory.CreateParameterizedConstructor(value) : null; - } - } - /// /// Gets or sets the function used to create the object. When set this function will override . /// This function is called with a collection of arguments which are defined by the collection. @@ -123,16 +82,13 @@ namespace Newtonsoft.Json.Serialization public ObjectConstructor OverrideCreator { get { return _overrideCreator; } - set - { - _overrideCreator = value; - _overrideConstructor = null; - } + set { _overrideCreator = value; } } internal ObjectConstructor ParameterizedCreator { get { return _parameterizedCreator; } + set { _parameterizedCreator = value; } } /// @@ -166,8 +122,6 @@ namespace Newtonsoft.Json.Serialization internal bool ExtensionDataIsJToken; private bool? _hasRequiredOrDefaultValueProperties; - private ConstructorInfo _parametrizedConstructor; - private ConstructorInfo _overrideConstructor; private ObjectConstructor _overrideCreator; private ObjectConstructor _parameterizedCreator; private JsonPropertyCollection _creatorParameters;