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

Replace BalanceTransactionSource class by IBalanceTransactionSource interface #1321

Merged
merged 1 commit into from
Oct 5, 2018

Conversation

ob-stripe
Copy link
Contributor

r? @remi-stripe
cc @stripe/api-libraries

Like #1320, but for BalanceTransactionSource.

I also fixed an issue with StringOrObject. Since the interface deserializer can now return null (in case of an unknown object), we need to handle this case in StringOrObject otherwise an exception would be raised when trying to access the Id attribute on the null object.

Copy link
Contributor

@remi-stripe remi-stripe left a comment

Choose a reason for hiding this comment

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

one minor comment before I can approve

// the ID from the raw JObject.
var id = ((JObject)value).SelectToken("id")?.ToString();
updateId(id);
updateObject(default(T));
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm glad you found that, I was planning to ask you about it since I felt we "lost" the ability to handle "unknown" types.

Out of curiosity, how does that work? IBalanceTransactionSource is an interface. It implements IHasId but it does not have an Id property. Where does the property go? I see in the test that it seems to go in SourceId but I don't think it's correct. If you have Source expanded, you expect Source to not be null and it would not make sense to write code that falls back to SourceId right?

Also we likely (absolutely?) want to deserialize Object too since it's the only way for someone to know what type is not handled properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, when encountering an unknown type:

  • SourceId is set to the ID
  • Source is set to a BalanceTransactionSource instance with the following properties:
    • Type is set to BalanceTransactionSourceType.Unknown
    • all other properties are null

Now, when encountering an unknown type:

  • SourceId is set to the ID
  • Source is set to null

So basically, instead of checking that Source.Type != BalanceTransactionSourceType.Unknown, now you just check that Source != null.

In both cases (before and after), you can check the unknown object type and the rest of the JSON via the StripeResponse.ResponseJson property on the top-level BalanceTransactiopn instance.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah okay I see what I misunderstood in all that deserialization. Part of me thought Object and Id would just magically work but it can't really have worked that way. And I assume having a small number of properties filled out is even more confusing than having the entire fields be null.

Thank you for always taking the time to explain this thoroughly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries. I also think it'd be useful to make the unknown object's name explicit in some way, but I think we'd need to add some logging capabilities to the library first. I'll try and look into that.

@remi-stripe remi-stripe self-assigned this Oct 5, 2018
@ob-stripe ob-stripe merged commit 99b5e2f into integration-next-major-version Oct 5, 2018
@ob-stripe ob-stripe deleted the ob-interface-bt-source branch October 5, 2018 12:28
@ob-stripe ob-stripe mentioned this pull request Oct 5, 2018
32 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants