-Improved support for deserializing objects using non-default constructors
-JsonConverterAttribute now allowed on constructor parameters -JsonPropertyAttribute now allowed on constructor parameters
This commit is contained in:
+84
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class NameContainer
|
||||
{
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
||||
public class NameContainerConverter : JsonConverter
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
NameContainer nameContainer = value as NameContainer;
|
||||
|
||||
if (nameContainer != null)
|
||||
writer.WriteValue(nameContainer.Value);
|
||||
else
|
||||
writer.WriteNull();
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
NameContainer nameContainer = new NameContainer();
|
||||
nameContainer.Value = (string)reader.Value;
|
||||
|
||||
return nameContainer;
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType == typeof(NameContainer);
|
||||
}
|
||||
}
|
||||
|
||||
public class PublicParametizedConstructorRequiringConverterTestClass
|
||||
{
|
||||
private readonly NameContainer _nameContainer;
|
||||
|
||||
public PublicParametizedConstructorRequiringConverterTestClass(NameContainer nameParameter)
|
||||
{
|
||||
_nameContainer = nameParameter;
|
||||
}
|
||||
|
||||
public NameContainer Name
|
||||
{
|
||||
get { return _nameContainer; }
|
||||
}
|
||||
}
|
||||
|
||||
public class PublicParametizedConstructorRequiringConverterWithParameterAttributeTestClass
|
||||
{
|
||||
private readonly NameContainer _nameContainer;
|
||||
|
||||
public PublicParametizedConstructorRequiringConverterWithParameterAttributeTestClass([JsonConverter(typeof(NameContainerConverter))] NameContainer nameParameter)
|
||||
{
|
||||
_nameContainer = nameParameter;
|
||||
}
|
||||
|
||||
public NameContainer Name
|
||||
{
|
||||
get { return _nameContainer; }
|
||||
}
|
||||
}
|
||||
|
||||
public class PublicParametizedConstructorRequiringConverterWithPropertyAttributeTestClass
|
||||
{
|
||||
private readonly NameContainer _nameContainer;
|
||||
|
||||
public PublicParametizedConstructorRequiringConverterWithPropertyAttributeTestClass(NameContainer name)
|
||||
{
|
||||
_nameContainer = name;
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(NameContainerConverter))]
|
||||
public NameContainer Name
|
||||
{
|
||||
get { return _nameContainer; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class PublicParametizedConstructorTestClass
|
||||
{
|
||||
private readonly string _name;
|
||||
|
||||
public PublicParametizedConstructorTestClass(string name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class PublicParametizedConstructorWithNonPropertyParameterTestClass
|
||||
{
|
||||
private readonly string _name;
|
||||
|
||||
public PublicParametizedConstructorWithNonPropertyParameterTestClass(string nameParameter)
|
||||
{
|
||||
_name = nameParameter;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
}
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class PublicParametizedConstructorWithPropertyNameConflict
|
||||
{
|
||||
private readonly int _value;
|
||||
|
||||
public PublicParametizedConstructorWithPropertyNameConflict(string name)
|
||||
{
|
||||
_value = Convert.ToInt32(name);
|
||||
}
|
||||
|
||||
public int Name
|
||||
{
|
||||
get { return _value; }
|
||||
}
|
||||
}
|
||||
|
||||
public class PublicParametizedConstructorWithPropertyNameConflictWithAttribute
|
||||
{
|
||||
private readonly int _value;
|
||||
|
||||
public PublicParametizedConstructorWithPropertyNameConflictWithAttribute([JsonProperty("name")]string nameParameter)
|
||||
{
|
||||
_value = Convert.ToInt32(nameParameter);
|
||||
}
|
||||
|
||||
public int Name
|
||||
{
|
||||
get { return _value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user