Let’s say I’m using Spring and have a controller that returns a model containing a field data that is an instance of Jackson’s ObjectNode. Within data I have a StringBuilder named log.
In the JSP I use
${data}
and I get this output:
{"log":hello world}
Now if I want to access log I thought I could use
${data["log"]}
but all I get is
javax.el.PropertyNotFoundException: Property 'log' not found on type org.codehaus.jackson.node.ObjectNode
javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:214)
javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:191)
javax.el.BeanELResolver.property(BeanELResolver.java:300)
javax.el.BeanELResolver.getValue(BeanELResolver.java:81)
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
org.apache.el.parser.AstValue.getValue(AstValue.java:123)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:938)
:
${data.log} shows the same.
I know that according to the EL data.log looks for a method getLog() on data, but IIRC Maps<?,?> support this kind of access to its keys. Is there any similar way to make it work with Jackson? Or if that just doesn’t work this way, how would you do this?
Now that I revisited this issue, I wrote my own ELResolver for ArrayNode and ObjectNode. Helpful links were
EDIT:
As far as the ArrayNode is concerned, it helped me to look at Tomcat’s ArrayELResolver. It’s pretty easy to go from there.