Add JsonContract.InternalConverter (#2028)
This commit is contained in:
@@ -47,6 +47,8 @@ using System.Reflection;
|
||||
using Newtonsoft.Json.Utilities;
|
||||
using System.Globalization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Serialization
|
||||
{
|
||||
@@ -812,5 +814,25 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
Assert.AreEqual(Required.AllowNull, allowNull.Required);
|
||||
Assert.AreEqual(true, allowNull.IsRequiredSpecified);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InternalConverter_Object_NotSet()
|
||||
{
|
||||
DefaultContractResolver resolver = new DefaultContractResolver();
|
||||
|
||||
JsonObjectContract contract = (JsonObjectContract)resolver.ResolveContract(typeof(object));
|
||||
|
||||
Assert.IsNull(contract.InternalConverter);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InternalConverter_Regex_Set()
|
||||
{
|
||||
DefaultContractResolver resolver = new DefaultContractResolver();
|
||||
|
||||
JsonContract contract = resolver.ResolveContract(typeof(Regex));
|
||||
|
||||
Assert.IsInstanceOf(typeof(RegexConverter), contract.InternalConverter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,9 +131,12 @@ namespace Newtonsoft.Json.Serialization
|
||||
/// <value>The converter.</value>
|
||||
public JsonConverter Converter { get; set; }
|
||||
|
||||
// internally specified JsonConverter's to override default behavour
|
||||
// checked for after passed in converters and attribute specified converters
|
||||
internal JsonConverter InternalConverter { get; set; }
|
||||
/// <summary>
|
||||
/// Gets the internally resolved <see cref="JsonConverter"/> for the contract's type.
|
||||
/// This converter is used as a fallback converter when no other converter is resolved.
|
||||
/// Setting <see cref="Converter"/> will always override this converter.
|
||||
/// </summary>
|
||||
public JsonConverter InternalConverter { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets all methods called immediately after deserialization of the object.
|
||||
|
||||
@@ -133,12 +133,14 @@ namespace Newtonsoft.Json.Serialization
|
||||
protected bool Equals(NamingStrategy other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return GetType() == other.GetType() &&
|
||||
ProcessDictionaryKeys == other.ProcessDictionaryKeys &&
|
||||
ProcessExtensionDataNames == other.ProcessExtensionDataNames &&
|
||||
OverrideSpecifiedNames == other.OverrideSpecifiedNames;
|
||||
ProcessDictionaryKeys == other.ProcessDictionaryKeys &&
|
||||
ProcessExtensionDataNames == other.ProcessExtensionDataNames &&
|
||||
OverrideSpecifiedNames == other.OverrideSpecifiedNames;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user