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 a helper method to parse maps of objects #53096

Closed
wants to merge 1 commit into from

Conversation

romseygeek
Copy link
Contributor

We have several requests and responses that pass around maps of objects,
both multi-valued with keys acting as labels for indexes or fields (for example
in GetIndex or GetMappings), or single-valued with the label pointing to a field
(for example in queries run against a single field such as term or intervals).
All of these current have hand-rolled parsing code, because there's not an easy
way to tell ObjectParser how to handle them.

This commit adds a helper method to XContentParserUtils that, given an object
parser and a json map, will parse each value using the map key as a context and
return a map of keys to objects. You can also specify whether or not the map
should have more than one value.

@romseygeek romseygeek added >enhancement :Core/Infra/Core Core issues without another label v8.0.0 v7.7.0 labels Mar 4, 2020
@romseygeek romseygeek requested a review from nik9000 March 4, 2020 11:11
@romseygeek romseygeek self-assigned this Mar 4, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Core)

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

There is a map method on XContentParser that takes a bunch of parameters. I don't think it is quite the same as this, but it is pretty similar. Maybe this should be on XContentParser, along side that map method?

@romseygeek
Copy link
Contributor Author

Oops, yes, XContentParser.map() does basically everything this one does except check for singletons. I think a singleton map parser is useful though; I'll open a new PR to add a singletonMap function to XContentParser

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

Successfully merging this pull request may close these issues.

4 participants