public void HasSettings_DefaultObject_ReturnsFalse() { // Arrange var settings = new DeserializationOptions(); // Act var result = settings.HasSettings; // Assert Assert.False(result); }
public void HasSettings_WithCustomObjectCreator_ReturnsTrue() { // Arrange var settings = new DeserializationOptions() { CustomObjectCreator = new Mock<ICustomObjectCreator>().Object }; // Act var result = settings.HasSettings; // Assert Assert.True(result); }
public void DeserializationOptions_Modification_UpdatesEffectiveSettings() { // Arrange var options = new DeserializationOptions(); var effectiveSettings = new JsonSerializerSettings(); var serializer = new Mock<DefaultSerializer> { CallBase = true }; serializer.Setup(p => p.GetDeserializationSettings(It.IsAny<JsonSerializerSettings>(), options)) .Returns(effectiveSettings); // Act serializer.Object.DeserializationOptions = options; // Assert Assert.AreEqual(effectiveSettings, serializer.Object.EffectiveDeserializationSettings); }
protected internal virtual JsonSerializerSettings GetDeserializationSettings(JsonSerializerSettings baseSettings, DeserializationOptions options) { if ((options == null) || !options.HasSettings) { // No custom deserialization, so use baseSettings directly return(baseSettings); } var settings = new JsonSerializerSettings() { CheckAdditionalContent = baseSettings.CheckAdditionalContent, ConstructorHandling = baseSettings.ConstructorHandling, Context = baseSettings.Context, ContractResolver = baseSettings.ContractResolver, Converters = new List <JsonConverter>(baseSettings.Converters), Culture = baseSettings.Culture, DateFormatHandling = baseSettings.DateFormatHandling, DateFormatString = baseSettings.DateFormatString, DateParseHandling = baseSettings.DateParseHandling, DateTimeZoneHandling = baseSettings.DateTimeZoneHandling, DefaultValueHandling = baseSettings.DefaultValueHandling, FloatFormatHandling = baseSettings.FloatFormatHandling, FloatParseHandling = baseSettings.FloatParseHandling, Formatting = baseSettings.Formatting, MaxDepth = baseSettings.MaxDepth, NullValueHandling = baseSettings.NullValueHandling, ObjectCreationHandling = baseSettings.ObjectCreationHandling, PreserveReferencesHandling = baseSettings.PreserveReferencesHandling, ReferenceLoopHandling = baseSettings.ReferenceLoopHandling, StringEscapeHandling = baseSettings.StringEscapeHandling, TraceWriter = baseSettings.TraceWriter, TypeNameHandling = baseSettings.TypeNameHandling, #if NET452 // There is an incompatibility between the .Net Desktop and .Net Standard assembilies of Newtonsoft.Json // Which causes these settings to fail if the .Net Standard version of Couchbase is consumed by a .Net Desktop // assembly. As a workaround, don't try to copy them in the .Net Standard version. Binder = baseSettings.Binder, TypeNameAssemblyFormat = baseSettings.TypeNameAssemblyFormat, #endif }; #pragma warning disable 618 if (baseSettings.ReferenceResolver != null) #pragma warning restore 618 { // Backwards compatibility issue in Newtonsoft.Json 7.0.1 causes setting a null reference resolver to error instead of using default #pragma warning disable 618 settings.ReferenceResolver = baseSettings.ReferenceResolver; #pragma warning restore 618 } if (options.CustomObjectCreator != null) { settings.Converters.Add(new JsonNetCustomObjectCreatorWrapper(options.CustomObjectCreator)); } return(settings); }
protected internal virtual JsonSerializerSettings GetDeserializationSettings(JsonSerializerSettings baseSettings, DeserializationOptions options) { if ((options == null) || !options.HasSettings) { // No custom deserialization, so use baseSettings directly return(baseSettings); } var settings = new JsonSerializerSettings() { Binder = baseSettings.Binder, CheckAdditionalContent = baseSettings.CheckAdditionalContent, ConstructorHandling = baseSettings.ConstructorHandling, Context = baseSettings.Context, ContractResolver = baseSettings.ContractResolver, Converters = new List <JsonConverter>(baseSettings.Converters), Culture = baseSettings.Culture, DateFormatHandling = baseSettings.DateFormatHandling, DateFormatString = baseSettings.DateFormatString, DateParseHandling = baseSettings.DateParseHandling, DateTimeZoneHandling = baseSettings.DateTimeZoneHandling, DefaultValueHandling = baseSettings.DefaultValueHandling, FloatFormatHandling = baseSettings.FloatFormatHandling, FloatParseHandling = baseSettings.FloatParseHandling, Formatting = baseSettings.Formatting, MaxDepth = baseSettings.MaxDepth, NullValueHandling = baseSettings.NullValueHandling, ObjectCreationHandling = baseSettings.ObjectCreationHandling, PreserveReferencesHandling = baseSettings.PreserveReferencesHandling, ReferenceLoopHandling = baseSettings.ReferenceLoopHandling, StringEscapeHandling = baseSettings.StringEscapeHandling, TraceWriter = baseSettings.TraceWriter, TypeNameAssemblyFormat = baseSettings.TypeNameAssemblyFormat, TypeNameHandling = baseSettings.TypeNameHandling }; if (baseSettings.ReferenceResolver != null) { // Backwards compatibility issue in Newtonsoft.Json 7.0.1 causes setting a null reference resolver to error instead of using default settings.ReferenceResolver = baseSettings.ReferenceResolver; } if (options.CustomObjectCreator != null) { settings.Converters.Add(new JsonNetCustomObjectCreatorWrapper(options.CustomObjectCreator)); } return(settings); }