Re: how to make freeMarker simply call toString?
Daniel Dekany <[email protected]> Sun, 30 Mar 2014 16:35:03 +0200
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Hello,
The way it works currently is that if FreeMarker doesn't know how to
make string out of a value (an FTL sequence or FTL hash in your case),
it will check if the *wrapped* value (which is made by the
ObjectWrapper from the plain Java object) implements
TemplateScalarModel, and if it does, it will use that to generate the
text to print. So, everything is possible with a custom ObjectWrapper.
As of how to achieve this with an out-of-the box object wrapper...
BeansWrapper does this if you don't
beansWrapper.setSimpleMapWrapper(true) it, except for arrays, but the
toString output of arrays is useless anyway. However, I wouldn't
recommend setSimpleMapWrapper(false), because it mixes the method
names with the keys in the map, which can get quite confusing.
But maybe I can give a better answer (or an RFE...) if I know why is
this needed. So why?
--
Thanks,
Daniel Dekany
Sunday, March 30, 2014, 12:16:07 PM, Vitaliy Semochkin wrote:
> Hello,
>
> I want to configure Freemarker
> in order to make it replace
>
> every ${object}, ${object.someField}, ${object.someMethod()}
> in my template with a toString value for the returned object.
> Even if it is an array, list, map or collection.
>
> How to configure freemarkert in order to do so?
>
> Regards,
> Vitaliy
>
------------------------------------------------------------------------------