Handle JSON null when reading object/array-typed properties - #73
Merged
Conversation
JSONSchemaObject>>readUsing: and JSONSchemaArray>>readUsing: went
straight to a structural parse (parseMapKeysDo:/parseListDo:, expecting
{ or [ respectively) with no concept of null, even though any property
can legitimately be JSON null regardless of its declared type - Stripe's
responses do this constantly (address, discount, items, and most other
optional fields are null unless set). Added a shared
JSONSchema>>peekNullThenReadUsing:ifNotNull: (uses parseConstantDo:, which
does not consume the stream on a non-match, to peek for null/true/false
before committing to the structural read) and wired both readUsing:
methods through it. A literal true/false where an object/array was
expected now raises a clear JSONTypeError instead of an opaque
NeoJSONParseError ('{ expected'/'[ expected').
Found the same way as the rest of today's fixes: driving OpenApiClient
against the real Stripe spec + a live stripe-mock instance. The full
Customer and Subscription response bodies - both deeply nested, both
full of null fields - now read back correctly end to end.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JSONSchemaObject>>readUsing: and JSONSchemaArray>>readUsing: went straight to a structural parse (parseMapKeysDo:/parseListDo:, expecting { or [ respectively) with no concept of null, even though any property can legitimately be JSON null regardless of its declared type - Stripe's responses do this constantly (address, discount, items, and most other optional fields are null unless set). Added a shared JSONSchema>>peekNullThenReadUsing:ifNotNull: (uses parseConstantDo:, which does not consume the stream on a non-match, to peek for null/true/false before committing to the structural read) and wired both readUsing: methods through it. A literal true/false where an object/array was expected now raises a clear JSONTypeError instead of an opaque NeoJSONParseError ('{ expected'/'[ expected').
Found the same way as the rest of today's fixes: driving OpenApiClient against the real Stripe spec + a live stripe-mock instance. The full Customer and Subscription response bodies - both deeply nested, both full of null fields - now read back correctly end to end.