tags:

views:

241

answers:

1

Using Struts 2.1.6, xwork 2.1.2 and ognl 2.6.11 In my struts action I have a Map that I am fetching elements from using OGNL. If the key I am using to fetch with does not exist in the map then OGNL returns an empty object array, that OGNL converts to a string and I get the object reference java.lang.Object@6.... This occurs in several places and seems to be the the map having the value generic specified as an Object. This is not something I can change. I have traced the problem for a while, but when I ended up deep into the guts of the OGNL code and I did not see a light at the end of the tunnel. Currently I am going to go with an ugly hack of checking the string return to see if it starts with "java.lang.Object@" and if so return an empty string. I don't like the solution but thats what time permits. Has anyone encountered a similar problem?

Also, where did OpenSymphony go? updates to their webiste appear to have dried up, the user forums say they are being converted to Google Groups no later than Nov-12-09

A: 

This is a problem with null values: if value is null, default behavior is to create a value using default constructor. Since the value type of your map is Object, new Objects are created where null is.

In order to stop this behavior:

  • use @CreateIfNull( value = false )
  • use mapName_CreateIfNull=false in classname-convertion.properties file.
Ula Krukar