Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryStringSerializer backs out on null values #32

Closed
GoogleCodeExporter opened this issue Aug 27, 2015 · 4 comments
Closed

QueryStringSerializer backs out on null values #32

GoogleCodeExporter opened this issue Aug 27, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

Given the following class:

public class C
{
  public int? A { get; set; }
  public int? B { get; set; }
}

The following statements do not show correct output:

var c1 = new C { A = 1, B = 2 };
var c2 = new C { A = null, B = 2 };
var s1 = QueryStringSerializer.SerializeToString(c1); // = "A=1&B=2"
var s2 = QueryStringSerializer.SerializeToString(c2); // = ""

After some testing it appears all null properties will lead to following 
properties not being output. I think it's due to WriteQueryString in 
ServiceStack.Text.Common.WriteType
:

foreach (var propertyWriter in PropertyWriters)
{
  var propertyValue = propertyWriter.GetterFn((T)value);
  if (propertyValue == null) return;
  ...
}

Looks like that return should be a break.

Original issue reported on code.google.com by GrimaceO...@gmail.com on 25 Aug 2010 at 6:39

@GoogleCodeExporter
Copy link
Author

er... I meant: continue, of course ;)

Original comment by GrimaceO...@gmail.com on 25 Aug 2010 at 6:41

@GoogleCodeExporter
Copy link
Author

Yep that would do the trick.

Thanks for reporting and finding the bug - you're example is now apart of 
ServiceStack,  as a test case :)

Fix is attached.

Original comment by demis.be...@gmail.com on 25 Aug 2010 at 7:01

  • Changed state: Fixed

Attachments:

@GoogleCodeExporter
Copy link
Author

I thought Ayende was a machine, but I'm beginning to suspect you were made in 
the same factory. Thanks again for the quick response!

Original comment by GrimaceO...@gmail.com on 25 Aug 2010 at 7:14

@GoogleCodeExporter
Copy link
Author

lol - I just like fixing the easy ones :)

Original comment by demis.be...@gmail.com on 25 Aug 2010 at 7:19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant