GrailsParameterMap is not serializable in Grails
grails, java
Solution
The problem is that `params` map type (`GrailsParameterMap`) which holds parameters in controller doesn't implement `Serializable` interface, that is why you get exception. Solution I now think of require that you create a new hashmap specifically for `params` and copy all the parameters there and save that `HashMap` to session, eg:
// this is my pseudocode - haven't been doing groovy and java for long time
java.util.Map paramMap = new java.util.HashMap() // copy params here
foreach(p in params)
{
paramMap.put(p.Key, p.Value)
}
java.util.Map nextUrl = new java.util.HashMap()
nextUrl.put("controller", controllerName)
nextUrl.put("action", actionName)
nextUrl.put("params", paraMap) // <- note paramMap, not params!
session.setAttribute("nextUrl", nextUrl)
Problem
In my grails application running on tomcat and with session replication in place among app servers, When I save a map in http session as follows, I got an exception GrailsParameterMap is not Serializable - ``` session.nextUrl = [controller: controllerName, action: actionName, params: params] ``` When I change the above snippet as follows, then also I got the same exception even java.util.HashMap implements Serializable. ``` java.util.Map nextUrl = new java.util.HashMap() nextUrl.put("controller", controllerName) nextUrl.put("action", actionName) nextUrl.put("params", params) session.setAttribute("nextUrl", nextUrl) ``` I can also see that the get/set in session is working fine. How can I solve this issue. Thanks in advance, Prashant