java - How to access as JsonNode from session | ${user.get()} -
i'm creating simple session object (jsonnode)
jsonnode me = mapper.readvalue(result, jsonnode.class); httpsession session = request.getsession(true); session.setattribute("user", me);
the trying access this.
${user} // works print {"id":8,"name":"jones"..} ${user.id} // trows error "property 'id' not found on type org.codehaus.jackson.node.objectnode" ${user.get(0)} // nothing printed out. ${user.size()} // return 4, id,name,username,token
how re factor code fix problem, or selector?
the version @mindas suggested should work, unless using tomcat 7. seems tomcat 7 has bug when calling overloaded methods jsp el (see issue here). using tomcat 7?
the ${user.get(0)}
isn't printing because method accessing value of specified element of array node. yours not array node , if use ${user.get("id")}
should value id
field, unless on tomcat 7 error cannot convert id of type class java.lang.string int
.
you try quick , dirty test ${user.findvalue("id")}
, see if @ least result, if don't mind me saying, think better if not expose raw object jsonnode
jsp sort of user
pojo getters , setters id
, name
, username
, token
instead. use ${user.id}
in jsp , have no issue tomcat.
Comments
Post a Comment