I have a Struts 2 application (JDK 1.7, Struts 2.2.1) that contains a list of filtering criteria stored as strings on a map.
Map< String, String > m_filters = new HashMap< String, String >(); public Map< String, String > getFilters() { return m_filters; }
I am passing a URL formatted as follows:
http://myserver.com/myapp/GenerateReport.action?reportID=Whatever&filters.fromDate=0&filters.toDate=2000000000&filters.FcsType=piv_cardholder_3kp&detailed=true
Despite the fact that the map has both keys and value types specified as String, it tries to get the value from this
Map< String, String > filters = getFilters(); String value = filters.get( "fromDate" );
throws this exception:
java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.lang.String
I reproduced this in unit test and confirmed in the debugger that Struts 2 seems to create String [1] instead of String for each of the parameters. those. it is a string array of length 1, with the only string being the expected value ("0" in this case).
My question is: Is this a bug in Struts2, or am I doing something wrong?
If this is an error, is there a known workaround?
Shawn D.
source share