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

Add Type Check to Strict Extractor #34

Merged
merged 2 commits into from
Jan 8, 2025
Merged

Add Type Check to Strict Extractor #34

merged 2 commits into from
Jan 8, 2025

Conversation

rmarrowstone
Copy link
Contributor

Search paths on field names, indexed elements or wildcards imply an
expectation for container types. Before this change, a search path
looking for a field would simply not be invoked if the data was not
a struct. With this change, users can elect to have an Exception thrown
when data does not meet the implied type expectations of their paths.

The type check is performed after any callback for the parent itself:
that is not known to be mistyped by the paths.

It is only implemented for the "strict" matcher and the change to the
API reflects that.

*/
public PathExtractorBuilder<T> withSearchPath(final List<PathComponent> pathComponents,
final BiFunction<IonReader, T, Integer> callback) {
return withSearchPath(pathComponents, callback, new String[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

We might as well use a constant for new String[0].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was actually a change from the other PR that I accidentally included here. I addressed it in that PR.

Copy link
Contributor

@desaikd desaikd left a comment

Choose a reason for hiding this comment

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

LGTM!

* The type check is performed _after_ any callbacks registered for the current path and
* _before_ any child matches are attempted.
*/
public PathExtractor<T> buildStrict(final boolean strictTyping) {
Copy link
Contributor

Choose a reason for hiding this comment

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

(Suggestion) Maybe we can make this private and have a buildStrictWithTypeCheck. It just sounds redundant to say PathExtractorBuilder.buildStrict(true).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea.. but it means that on the call-site I don't need to add branches if i already have a boolean flag.

Search paths on field names, indexed elements or wildcards imply an
expectation for container types. Before this change, a search path
looking for a field would simply not be invoked if the data was not
a struct. With this change, users can elect to have an Exception thrown
when data does not meet the implied type expectations of their paths.

The type check is performed after any callback for the parent itself:
that is not known to be mistyped by the paths.

It is only implemented for the "strict" matcher and the change to the
API reflects that.
@rmarrowstone rmarrowstone merged commit df9a213 into master Jan 8, 2025
4 checks passed
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.

3 participants