I just ran into something unexpected. If I set up a context like this:
Context context = Context.newBuilder(contextData)
.resolver(JsonNodeValueResolver.INSTANCE_.build()
And then use that to apply to a template that includes a partial with values like:
{{> other key="value" }}
The value of key is not available in the "other" template. However, if I do this:
Context context = Context.newBuilder(contextData)
.resolver(JsonNodeValueResolver.INSTANCE,
MapValueResolver.INSTANCE,
JavaBeanValueResolver.INSTANCE).build()
everything works as expected. From the documentation and the examples I assumed that new Context objects in the stack would have their own, default resolver. If nothing else, docs like these:
https://jknack.github.io/handlebars.java/jackson.html don't mention that messing with the resolver will potentially break partial. Also, the fix above seems brittle as I have hard coded the default resolvers. Should those ever change my templates would break. I'd think a "combineResolver" method which is the analog of the "combine" method on the context builder would be a nice addition.
So, just wanted to double check, is the fix above the right one? Any way to protect myself against the addition, removal, or change of the default resolvers in the future?
Thanks,
Oliver