Stream: hapi
Topic: iterating a resource
Andrew Broadbent (Jan 16 2017 at 16:44):
Does anyone know how to iterate the children of an IResource in the java api? I have an api which in a nutshell takes a path 'Basic.meta.x' and returns whatever it finds at the point. I'm having trouble though as I only seem to be able to access properties of a resource via the helper functions, which would mean for every property/resource I'd have to have a lot of special case code. I've seen the function 'getAllPopulatedChildElementsOfType', but it takes a type rather than the name of the child.
Thanks for any help
James Agnew (Jan 18 2017 at 19:45):
Hi Andrew,
Do you mean like you have a resource instance, and you want to write code that will return whatever value happens to be at the path "Basic.meta.versionId" by passing in that string?
If so, this could be accomplished by using something like:
versionId - ctx.newTerser().getSingleValueOrNull(resource, "Basic.meta.versionId")
The Terser has a bunch of similar methods that might also be of use.
Last updated: Apr 12 2022 at 19:14 UTC