Skip to content

Commit

Permalink
Merge pull request #1309 from esdrubal/json
Browse files Browse the repository at this point in the history
Improved Json deserialization of floating-point numbers.
  • Loading branch information
marek-safar committed Sep 25, 2014
2 parents 40ccf51 + 92a4fd2 commit 410af9c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Expand Up @@ -264,7 +264,7 @@ object ReadInstanceDrivenObject ()
if (double.TryParse (v, NumberStyles.None, CultureInfo.InvariantCulture, out dbl))
return dbl;
decimal dec;
if (decimal.TryParse (v, NumberStyles.None, CultureInfo.InvariantCulture, out dec))
if (decimal.TryParse (v, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out dec))
return dec;
throw SerializationError (String.Format ("Invalid JSON input: {0}", v));
default:
Expand Down
Expand Up @@ -855,5 +855,16 @@ public void UnicodeEncodingAutoDetect ()
r.ReadStartElement ();
r.Read ();
}

[Test]
public void ReadNumberAsObject ()
{
const double testValue = 42.42D;
var serializer = new DataContractJsonSerializer (typeof (object));
var serializedStream = GetInput (testValue.ToString (CultureInfo.InvariantCulture));
var deserializedValue = serializer.ReadObject (serializedStream);
Assert.AreEqual (typeof (decimal), deserializedValue.GetType ());
Assert.AreEqual (testValue, (decimal) deserializedValue);
}
}
}

0 comments on commit 410af9c

Please sign in to comment.