-Explicit culture for tests
-Tests
This commit is contained in:
@@ -368,6 +368,20 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
Assert.AreEqual("fff", obj.Field1);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void PopulateTest()
|
||||
{
|
||||
var test = JsonConvert.DeserializeObject<PopulateWithNullJsonTest>("{\"IntValue\":null}");
|
||||
Console.WriteLine("IntValue:{0}", test.IntValue);
|
||||
}
|
||||
|
||||
public class PopulateWithNullJsonTest
|
||||
{
|
||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate, NullValueHandling = NullValueHandling.Ignore)]
|
||||
[DefaultValue(6)]
|
||||
public int IntValue { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
#if !NET20
|
||||
|
||||
@@ -8374,6 +8374,46 @@ Path '', line 1, position 1.");
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void ParameterizedConstructorWithBasePrivateProperties()
|
||||
{
|
||||
var original = new DerivedConstructorType("Base", "Derived");
|
||||
|
||||
var serializerSettings = new JsonSerializerSettings();
|
||||
var jsonCopy = JsonConvert.SerializeObject(original, serializerSettings);
|
||||
|
||||
Console.WriteLine(original);
|
||||
|
||||
var clonedObject = JsonConvert.DeserializeObject<DerivedConstructorType>(jsonCopy, serializerSettings);
|
||||
|
||||
Assert.AreEqual("Base", clonedObject.BaseProperty);
|
||||
Assert.AreEqual("Derived", clonedObject.DerivedProperty);
|
||||
}
|
||||
|
||||
public class DerivedConstructorType : BaseConstructorType
|
||||
{
|
||||
public DerivedConstructorType(string baseProperty, string derivedProperty)
|
||||
: base(baseProperty)
|
||||
{
|
||||
DerivedProperty = derivedProperty;
|
||||
}
|
||||
|
||||
[JsonProperty]
|
||||
public string DerivedProperty { get; private set; }
|
||||
}
|
||||
|
||||
|
||||
public class BaseConstructorType
|
||||
{
|
||||
[JsonProperty]
|
||||
public string BaseProperty { get; private set; }
|
||||
|
||||
public BaseConstructorType(string baseProperty)
|
||||
{
|
||||
BaseProperty = baseProperty;
|
||||
}
|
||||
}
|
||||
|
||||
public class ErroringJsonConverter : JsonConverter
|
||||
{
|
||||
public ErroringJsonConverter(string s)
|
||||
|
||||
@@ -23,6 +23,11 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
#if NET20
|
||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||
#else
|
||||
using System.Linq;
|
||||
#endif
|
||||
#if !(PORTABLE || PORTABLE40)
|
||||
using System.Collections.ObjectModel;
|
||||
#if !(NET35 || NET20)
|
||||
@@ -1836,6 +1841,55 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
Assert.AreEqual(1UL, item.WantedUnitID);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !(NET20 || NET35)
|
||||
[Test]
|
||||
public void GenericItemTypeCollection()
|
||||
{
|
||||
DataType data = new DataType();
|
||||
data.Rows.Add("key", new List<MyInterfaceImplementationType> { new MyInterfaceImplementationType() { SomeProperty = "property" } });
|
||||
string serialized = JsonConvert.SerializeObject(data, Formatting.Indented);
|
||||
|
||||
StringAssert.AreEqual(@"{
|
||||
""Rows"": {
|
||||
""key"": {
|
||||
""$type"": ""System.Collections.Generic.List`1[[Newtonsoft.Json.Tests.Serialization.MyInterfaceImplementationType, Newtonsoft.Json.Tests]], mscorlib"",
|
||||
""$values"": [
|
||||
{
|
||||
""SomeProperty"": ""property""
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}", serialized);
|
||||
|
||||
DataType deserialized = JsonConvert.DeserializeObject<DataType>(serialized);
|
||||
|
||||
Assert.AreEqual("property", deserialized.Rows["key"].First().SomeProperty);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public class DataType
|
||||
{
|
||||
public DataType()
|
||||
{
|
||||
Rows = new Dictionary<string, IEnumerable<IMyInterfaceType>>();
|
||||
}
|
||||
|
||||
[JsonProperty(ItemTypeNameHandling = TypeNameHandling.Auto, TypeNameHandling = TypeNameHandling.Auto)]
|
||||
public Dictionary<string, IEnumerable<IMyInterfaceType>> Rows { get; private set; }
|
||||
}
|
||||
|
||||
|
||||
public interface IMyInterfaceType
|
||||
{
|
||||
string SomeProperty { get; set; }
|
||||
}
|
||||
|
||||
public class MyInterfaceImplementationType : IMyInterfaceType
|
||||
{
|
||||
public string SomeProperty { get; set; }
|
||||
}
|
||||
|
||||
#if !(NETFX_CORE || ASPNETCORE50)
|
||||
|
||||
Reference in New Issue
Block a user