-Updated nuspec file for 4.0
-Added Load and Parse helper methods to JToken -Fixed performance issues when deserializing with partial type names -Fixed deserializing certain decimal values on classes with non-default constructors
This commit is contained in:
@@ -203,7 +203,7 @@ Parameter name: reader")]
|
||||
{
|
||||
new JsonTextReader(null);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unterminated string. Expected delimiter: '. Line 1, position 3.")]
|
||||
public void UnexpectedEndOfString()
|
||||
@@ -220,7 +220,7 @@ Parameter name: reader")]
|
||||
|
||||
Assert.AreEqual("h\0i", reader.Value);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unexpected end while parsing unicode character. Line 1, position 7.")]
|
||||
public void UnexpectedEndOfHex()
|
||||
@@ -228,7 +228,7 @@ Parameter name: reader")]
|
||||
JsonReader reader = new JsonTextReader(new StringReader(@"'h\u006"));
|
||||
reader.Read();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unterminated string. Expected delimiter: '. Line 1, position 3.")]
|
||||
public void UnexpectedEndOfControlCharacter()
|
||||
@@ -494,10 +494,10 @@ bye", reader.Value);
|
||||
string json = @"[""\u003c"",""\u5f20""]";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
|
||||
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual("<", reader.Value);
|
||||
|
||||
@@ -782,5 +782,27 @@ bye", reader.Value);
|
||||
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void ReadAsDecimal()
|
||||
{
|
||||
string json = @"{""decimal"":-7.92281625142643E+28}";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
||||
|
||||
decimal? d = reader.ReadAsDecimal();
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(typeof(decimal), reader.ValueType);
|
||||
Assert.AreEqual(-79228162514264300000000000000m, d);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.IsTrue(JToken.DeepEquals(new JValue(1), c.Values().ElementAt(0)));
|
||||
|
||||
JValue v;
|
||||
|
||||
|
||||
v = (JValue)JToken.ReadFrom(new JsonTextReader(new StringReader(@"""stringvalue""")));
|
||||
Assert.AreEqual("stringvalue", (string)v);
|
||||
|
||||
@@ -71,6 +71,20 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.AreEqual(1.1, (double)v);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Load()
|
||||
{
|
||||
JObject o = (JObject)JToken.Load(new JsonTextReader(new StringReader("{'pie':true}")));
|
||||
Assert.AreEqual(true, (bool)o["pie"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Parse()
|
||||
{
|
||||
JObject o = (JObject)JToken.Parse("{'pie':true}");
|
||||
Assert.AreEqual(true, (bool)o["pie"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Parent()
|
||||
{
|
||||
|
||||
@@ -4015,5 +4015,33 @@ keyword such as type of business.""
|
||||
Assert.AreEqual("Success", deserializedResponse.Name);
|
||||
Assert.IsTrue(deserializedResponse.Data.DeepEquals(response.Data));
|
||||
}
|
||||
|
||||
public abstract class Test<T>
|
||||
{
|
||||
public abstract T Value { get; set; }
|
||||
}
|
||||
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class DecimalTest : Test<decimal>
|
||||
{
|
||||
protected DecimalTest() { }
|
||||
public DecimalTest(decimal val)
|
||||
{
|
||||
Value = val;
|
||||
}
|
||||
|
||||
[JsonProperty]
|
||||
public override decimal Value { get; set; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnError()
|
||||
{
|
||||
var data = new DecimalTest(decimal.MinValue);
|
||||
var json = JsonConvert.SerializeObject(data);
|
||||
var obj = JsonConvert.DeserializeObject<DecimalTest>(json);
|
||||
|
||||
Assert.AreEqual(decimal.MinValue, obj.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user