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

Setting a field to null? #1954

Closed
clement911 opened this issue Mar 13, 2020 · 7 comments
Closed

Setting a field to null? #1954

clement911 opened this issue Mar 13, 2020 · 7 comments
Assignees

Comments

@clement911
Copy link
Contributor

If I understand correctly, setting an option's property to null will cause the field to not be sent over the wire.

If that is the case, how I can actually set a field to a null value (i.e clearing the value).

For example, if I want to clear the customer's phone number.

I can set CustomerUpdateOptions.Phone to null. But it won't be serialized at all right?

Unless I'm missing something obvious here...

@remi-stripe remi-stripe self-assigned this Mar 13, 2020
@remi-stripe
Copy link
Contributor

@clement911 In the API, if you pass an empty string it will unset the string field.

var options2 = new CustomerUpdateOptions {
  Email = "",
  Phone = "",
};
Customer customer2 = service.Update(customer.Id, options2);

This would return email: null and phone: null in the API.

@clement911
Copy link
Contributor Author

What if I want to set an empty string?
What about other types such as numerics and dates and bools?

@remi-stripe
Copy link
Contributor

You can't set an empty string in that case, it will just set the field to null already. This is how the API itself works, so it's not really specific to stripe-dotnet.

You can not unset number of booleans with stripe-dotnet though our API rarely supports this in the first place.

@clement911
Copy link
Contributor Author

hmm ok.
Seems like quite a limitation...

@clement911
Copy link
Contributor Author

Although I'm not sure if it's a big deal in practice...

@remi-stripe
Copy link
Contributor

In my experience, it's not. Most booleans are set to true or false, we rarely have a null "state". We're also moving more to enums instead to represent the "true/false/unset" state where it matters.

@clement911
Copy link
Contributor Author

Ok, thanks for the quick response.

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

No branches or pull requests

2 participants