Freemarker method cannot accept object as parameters

I am trying to pass Freemarker HashLiteral to my custom method as follows:

where item without quotes is an object given in ModelAndView. The {“item”: item} is correctly transformed to freemarker.core.HashLiteral$SequenceHash, but I cannot recover it in my method as I get following exception:

This happens even with href method having empty body:


It’s probably that href is a TemplateMethodModel instead of a TemplateMethodModelEx. The args argument in TemplateMethodModel.exec(args) is a List of String-s, hence FreeMarker tries to convert the value to a string, but it can only do that with string, date or number values. So just change it to TemplateMethodModelEx and then args will be a List of TemplateModel-s and hence accepts all kind of values.