Skip to content

Commit fb68cad

Browse files
committed
Merge pull request restsharp#429 from rlyczynski/BoolFromIntDeserialization
JsonDeserialize : int to bool
2 parents 4c3b2e9 + 02a978b commit fb68cad

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

RestSharp.Tests/JsonTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,19 @@ public void Can_Deserialize_Quoted_Primitive()
313313
Assert.Equal(28, p.Age);
314314
}
315315

316+
[Fact]
317+
public void Can_Deserialize_Int_to_Bool()
318+
{
319+
var doc = new JsonObject();
320+
doc["IsCool"] = 1;
321+
322+
var d = new JsonDeserializer();
323+
var response = new RestResponse { Content = doc.ToString() };
324+
var p = d.Deserialize<PersonForJson>(response);
325+
326+
Assert.True(p.IsCool);
327+
}
328+
316329
[Fact]
317330
public void Can_Deserialize_With_Default_Root()
318331
{

RestSharp/Deserializers/JsonDeserializer.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,7 @@ private object ConvertValue(Type type, object value)
172172

173173
if (type.IsPrimitive)
174174
{
175-
// no primitives can contain quotes so we can safely remove them
176-
// allows converting a json value like {"index": "1"} to an int
177-
var tmpVal = stringValue.Replace("\"", string.Empty);
178-
179-
return tmpVal.ChangeType(type, Culture);
175+
return value.ChangeType(type, Culture);
180176
}
181177
else if (type.IsEnum)
182178
{

0 commit comments

Comments
 (0)