Skip to content

Conversation

rlyczynski
Copy link
Contributor

Fixes bug where JsonDeserializer could not deserialize an integer to a boolean property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't figure out why this was here. The SimpleJson deserializer returns a string object with the value 1 (no quotes) if the json string is {"index": "1"}. So converting the value to a string to strip the quotes before you convert doesn't make sense and by doing this it wont allow you to convert something like {"index": 1} to a bool.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm not sure either. My guess is to handle this case:

[Fact]
+    public void Can_Deserialize_Int_to_Bool()
+    {
+      var d = new JsonDeserializer();
+      var response = new RestResponse { Content = "{\"IsCool\":\"1\"}" };
+      var p = d.Deserialize<PersonForJson>(response);
+
+      Assert.True(p.IsCool);
+    }

Does that test also pass before and after?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That test would pass neither before nor after the change. The Convert class can only convert the string "true" or "false" to a bool (http://msdn.microsoft.com/en-us/library/86hw82a3(v=vs.90).aspx).

This is the reason {"IsCool": 1} would fail before, because that line converts 1 to a string before trying to convert to bool.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. I wouldn't want that test to pass. ;)

Thanks for the contribution!

haacked added a commit that referenced this pull request Sep 26, 2013
@haacked haacked merged commit fb68cad into restsharp:master Sep 26, 2013
@haacked
Copy link
Contributor

haacked commented Sep 26, 2013

thumbs-up-judo

Thanks!

@rlyczynski rlyczynski deleted the BoolFromIntDeserialization branch September 26, 2013 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants