-Documentation
-Fixed potential casting error when writing JSON using a JsonReader
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
<h3>Conversion Rules</h3>
|
||||
<ul>
|
||||
<li>Elements remain unchanged. </li>
|
||||
<li>Attributes are prefixed with an @. </li>
|
||||
<li>Attributes are prefixed with an @ and should be at the start of the object. </li>
|
||||
<li>Single child text nodes are a value directly against an element, otherwise they
|
||||
are accessed via #text. </li>
|
||||
<li>The XML declaration and processing instructions are prefixed with ?. </li>
|
||||
|
||||
@@ -461,7 +461,8 @@ keyword such as type of business.""
|
||||
[Test]
|
||||
public void DateTimeTest()
|
||||
{
|
||||
List<DateTime> testDates = new List<DateTime> {
|
||||
List<DateTime> testDates = new List<DateTime>
|
||||
{
|
||||
new DateTime(100, 1, 1, 1, 1, 1, DateTimeKind.Local),
|
||||
new DateTime(100, 1, 1, 1, 1, 1, DateTimeKind.Unspecified),
|
||||
new DateTime(100, 1, 1, 1, 1, 1, DateTimeKind.Utc),
|
||||
@@ -487,7 +488,8 @@ keyword such as type of business.""
|
||||
[Test]
|
||||
public void DateTimeOffset()
|
||||
{
|
||||
List<DateTimeOffset> testDates = new List<DateTimeOffset> {
|
||||
List<DateTimeOffset> testDates = new List<DateTimeOffset>
|
||||
{
|
||||
new DateTimeOffset(new DateTime(100, 1, 1, 1, 1, 1, DateTimeKind.Utc)),
|
||||
new DateTimeOffset(2000, 1, 1, 1, 1, 1, TimeSpan.Zero),
|
||||
new DateTimeOffset(2000, 1, 1, 1, 1, 1, TimeSpan.FromHours(13)),
|
||||
@@ -1391,8 +1393,10 @@ keyword such as type of business.""
|
||||
{
|
||||
[DataMember]
|
||||
public string Name { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public int Age { get; set; }
|
||||
|
||||
public string NotIncluded { get; set; }
|
||||
}
|
||||
|
||||
@@ -1443,12 +1447,14 @@ keyword such as type of business.""
|
||||
Title = title;
|
||||
}
|
||||
|
||||
[DataMember]
|
||||
private string _name;
|
||||
[DataMember] private string _name;
|
||||
|
||||
[DataMember(Name = "_age")]
|
||||
private int Age { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
private int Rank { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "JsonTitle")]
|
||||
[DataMember(Name = "DataTitle")]
|
||||
private string Title { get; set; }
|
||||
@@ -2328,9 +2334,13 @@ keyword such as type of business.""
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class A
|
||||
{
|
||||
[JsonProperty("A1")]
|
||||
private string _A1;
|
||||
public string A1 { get { return _A1; } set { _A1 = value; } }
|
||||
[JsonProperty("A1")] private string _A1;
|
||||
|
||||
public string A1
|
||||
{
|
||||
get { return _A1; }
|
||||
set { _A1 = value; }
|
||||
}
|
||||
|
||||
[JsonProperty("A2")]
|
||||
private string A2 { get; set; }
|
||||
@@ -2341,9 +2351,13 @@ keyword such as type of business.""
|
||||
{
|
||||
public string B1 { get; set; }
|
||||
|
||||
[JsonProperty("B2")]
|
||||
string _B2;
|
||||
public string B2 { get { return _B2; } set { _B2 = value; } }
|
||||
[JsonProperty("B2")] private string _B2;
|
||||
|
||||
public string B2
|
||||
{
|
||||
get { return _B2; }
|
||||
set { _B2 = value; }
|
||||
}
|
||||
|
||||
[JsonProperty("B3")]
|
||||
private string B3 { get; set; }
|
||||
@@ -2456,26 +2470,17 @@ keyword such as type of business.""
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return _innerDictionary.Count;
|
||||
}
|
||||
get { return _innerDictionary.Count; }
|
||||
}
|
||||
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((IDictionary<string, T>)_innerDictionary).IsReadOnly;
|
||||
}
|
||||
get { return ((IDictionary<string, T>) _innerDictionary).IsReadOnly; }
|
||||
}
|
||||
|
||||
public ICollection<string> Keys
|
||||
{
|
||||
get
|
||||
{
|
||||
return _innerDictionary.Keys;
|
||||
}
|
||||
get { return _innerDictionary.Keys; }
|
||||
}
|
||||
|
||||
public T this[string key]
|
||||
@@ -2486,18 +2491,12 @@ keyword such as type of business.""
|
||||
_innerDictionary.TryGetValue(key, out value);
|
||||
return value;
|
||||
}
|
||||
set
|
||||
{
|
||||
_innerDictionary[key] = value;
|
||||
}
|
||||
set { _innerDictionary[key] = value; }
|
||||
}
|
||||
|
||||
public ICollection<T> Values
|
||||
{
|
||||
get
|
||||
{
|
||||
return _innerDictionary.Values;
|
||||
}
|
||||
get { return _innerDictionary.Values; }
|
||||
}
|
||||
|
||||
public void Add(KeyValuePair<string, T> item)
|
||||
@@ -2844,17 +2843,21 @@ keyword such as type of business.""
|
||||
|
||||
public class AA
|
||||
{
|
||||
[JsonProperty]
|
||||
protected int AA_field1;
|
||||
[JsonProperty] protected int AA_field1;
|
||||
protected int AA_field2;
|
||||
|
||||
[JsonProperty]
|
||||
protected int AA_property1 { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
protected int AA_property2 { get; private set; }
|
||||
|
||||
[JsonProperty]
|
||||
protected int AA_property3 { private get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
private int AA_property4 { get; set; }
|
||||
|
||||
protected int AA_property5 { get; private set; }
|
||||
protected int AA_property6 { private get; set; }
|
||||
|
||||
@@ -2877,21 +2880,27 @@ keyword such as type of business.""
|
||||
|
||||
public class BB : AA
|
||||
{
|
||||
[JsonProperty]
|
||||
public int BB_field1;
|
||||
[JsonProperty] public int BB_field1;
|
||||
public int BB_field2;
|
||||
|
||||
[JsonProperty]
|
||||
public int BB_property1 { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public int BB_property2 { get; private set; }
|
||||
|
||||
[JsonProperty]
|
||||
public int BB_property3 { private get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
private int BB_property4 { get; set; }
|
||||
|
||||
public int BB_property5 { get; private set; }
|
||||
public int BB_property6 { private get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public int BB_property7 { protected get; set; }
|
||||
|
||||
public int BB_property8 { protected get; set; }
|
||||
|
||||
public BB()
|
||||
@@ -3315,6 +3324,7 @@ keyword such as type of business.""
|
||||
{
|
||||
[JsonIgnore]
|
||||
public Product Ignored { get; set; }
|
||||
|
||||
public string First { get; set; }
|
||||
public int Second { get; set; }
|
||||
|
||||
@@ -3439,12 +3449,9 @@ keyword such as type of business.""
|
||||
set { _nameSpecified = value; }
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool WeightSpecified;
|
||||
[JsonIgnore] public bool WeightSpecified;
|
||||
|
||||
[JsonIgnore]
|
||||
[System.Xml.Serialization.XmlIgnoreAttribute]
|
||||
public bool HeightSpecified;
|
||||
[JsonIgnore] [System.Xml.Serialization.XmlIgnoreAttribute] public bool HeightSpecified;
|
||||
|
||||
[JsonIgnore]
|
||||
|
||||
@@ -3548,8 +3555,7 @@ keyword such as type of business.""
|
||||
public string FirstOrder;
|
||||
// Use the XmlIgnoreAttribute to ignore the
|
||||
// special field named "FirstOrderSpecified".
|
||||
[System.Xml.Serialization.XmlIgnoreAttribute]
|
||||
public bool FirstOrderSpecified;
|
||||
[System.Xml.Serialization.XmlIgnoreAttribute] public bool FirstOrderSpecified;
|
||||
}
|
||||
|
||||
public class FamilyDetails
|
||||
@@ -3735,6 +3741,7 @@ keyword such as type of business.""
|
||||
public struct StructWithAttribute
|
||||
{
|
||||
public string MyString { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public int MyInt { get; set; }
|
||||
}
|
||||
@@ -3794,7 +3801,10 @@ keyword such as type of business.""
|
||||
|
||||
public class DerivedEvent : LogEvent
|
||||
{
|
||||
public override string EventName { get { return "derived"; } }
|
||||
public override string EventName
|
||||
{
|
||||
get { return "derived"; }
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -3923,7 +3933,9 @@ keyword such as type of business.""
|
||||
[JsonProperty]
|
||||
public string IDoWork { get; private set; }
|
||||
|
||||
private Derived() { }
|
||||
private Derived()
|
||||
{
|
||||
}
|
||||
|
||||
internal Derived(string dontWork, string doWork)
|
||||
: base(dontWork)
|
||||
@@ -3938,7 +3950,9 @@ keyword such as type of business.""
|
||||
[JsonProperty]
|
||||
public string IDontWork { get; private set; }
|
||||
|
||||
protected Base() { }
|
||||
protected Base()
|
||||
{
|
||||
}
|
||||
|
||||
internal Base(string dontWork)
|
||||
{
|
||||
@@ -4035,7 +4049,7 @@ keyword such as type of business.""
|
||||
}
|
||||
|
||||
|
||||
static NullableStructPropertyClass deserialize(string serStr)
|
||||
private static NullableStructPropertyClass deserialize(string serStr)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<NullableStructPropertyClass>(
|
||||
serStr,
|
||||
@@ -4078,7 +4092,10 @@ keyword such as type of business.""
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class DecimalTest : Test<decimal>
|
||||
{
|
||||
protected DecimalTest() { }
|
||||
protected DecimalTest()
|
||||
{
|
||||
}
|
||||
|
||||
public DecimalTest(decimal val)
|
||||
{
|
||||
Value = val;
|
||||
@@ -4294,6 +4311,7 @@ keyword such as type of business.""
|
||||
get { return null; }
|
||||
set { }
|
||||
}
|
||||
|
||||
protected internal object this[object property]
|
||||
{
|
||||
get { return null; }
|
||||
@@ -4329,7 +4347,7 @@ keyword such as type of business.""
|
||||
Assert.AreEqual(63, commentTestClass.Values.Count);
|
||||
}
|
||||
|
||||
class DTOWithParameterisedConstructor
|
||||
private class DTOWithParameterisedConstructor
|
||||
{
|
||||
public DTOWithParameterisedConstructor(string A)
|
||||
{
|
||||
@@ -4341,7 +4359,7 @@ keyword such as type of business.""
|
||||
public int? B { get; set; }
|
||||
}
|
||||
|
||||
class DTOWithoutParameterisedConstructor
|
||||
private class DTOWithoutParameterisedConstructor
|
||||
{
|
||||
public DTOWithoutParameterisedConstructor()
|
||||
{
|
||||
@@ -4472,6 +4490,7 @@ keyword such as type of business.""
|
||||
{
|
||||
public DateTime InterfaceMember { get; set; }
|
||||
public string NewMember { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "newMemberWithProperty")]
|
||||
public string NewMemberWithProperty { get; set; }
|
||||
}
|
||||
@@ -4670,12 +4689,9 @@ keyword such as type of business.""
|
||||
_readonlyString = "default!";
|
||||
}
|
||||
|
||||
[JsonProperty]
|
||||
private string _privateString;
|
||||
[JsonProperty]
|
||||
private readonly string _readonlyString;
|
||||
[JsonProperty]
|
||||
internal string _internalString;
|
||||
[JsonProperty] private string _privateString;
|
||||
[JsonProperty] private readonly string _readonlyString;
|
||||
[JsonProperty] internal string _internalString;
|
||||
|
||||
public string UseValue()
|
||||
{
|
||||
@@ -4721,27 +4737,19 @@ keyword such as type of business.""
|
||||
public class BaseType
|
||||
{
|
||||
|
||||
[DataMember]
|
||||
public string zebra;
|
||||
[DataMember] public string zebra;
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class DerivedType : BaseType
|
||||
{
|
||||
[DataMember(Order = 0)]
|
||||
public string bird;
|
||||
[DataMember(Order = 1)]
|
||||
public string parrot;
|
||||
[DataMember]
|
||||
public string dog;
|
||||
[DataMember(Order = 3)]
|
||||
public string antelope;
|
||||
[DataMember]
|
||||
public string cat;
|
||||
[JsonProperty(Order = 1)]
|
||||
public string albatross;
|
||||
[JsonProperty(Order = -2)]
|
||||
public string dinosaur;
|
||||
[DataMember(Order = 0)] public string bird;
|
||||
[DataMember(Order = 1)] public string parrot;
|
||||
[DataMember] public string dog;
|
||||
[DataMember(Order = 3)] public string antelope;
|
||||
[DataMember] public string cat;
|
||||
[JsonProperty(Order = 1)] public string albatross;
|
||||
[JsonProperty(Order = -2)] public string dinosaur;
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -4883,6 +4891,25 @@ keyword such as type of business.""
|
||||
Assert.AreEqual(null, v2["Second"]);
|
||||
Assert.AreEqual(3, v2["Third"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UsingJsonTextWriter()
|
||||
{
|
||||
// The property of the object has to be a number for the cast exception to occure
|
||||
object o = new {p = 1};
|
||||
|
||||
var json = JObject.FromObject(o);
|
||||
|
||||
using (var sw = new StringWriter())
|
||||
using (var jw = new JsonTextWriter(sw))
|
||||
{
|
||||
jw.WriteToken(json.CreateReader());
|
||||
jw.Flush();
|
||||
|
||||
string result = sw.ToString();
|
||||
Assert.AreEqual(@"{""p"":1}", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class UriGuidTimeSpanTestClass
|
||||
|
||||
@@ -353,16 +353,16 @@ namespace Newtonsoft.Json
|
||||
WriteComment(reader.Value.ToString());
|
||||
break;
|
||||
case JsonToken.Integer:
|
||||
WriteValue((long)reader.Value);
|
||||
WriteValue(Convert.ToInt64(reader.Value));
|
||||
break;
|
||||
case JsonToken.Float:
|
||||
WriteValue((double)reader.Value);
|
||||
WriteValue(Convert.ToDouble(reader.Value));
|
||||
break;
|
||||
case JsonToken.String:
|
||||
WriteValue(reader.Value.ToString());
|
||||
break;
|
||||
case JsonToken.Boolean:
|
||||
WriteValue((bool)reader.Value);
|
||||
WriteValue(Convert.ToBoolean(reader.Value));
|
||||
break;
|
||||
case JsonToken.Null:
|
||||
WriteNull();
|
||||
|
||||
Reference in New Issue
Block a user