sunmingtao / sample-code

3 stars 4 forks source link

Freemarker: Can't convert boolean to string automatically, because the "boolean_format" setting was "true,false" #128

Closed sunmingtao closed 4 years ago

sunmingtao commented 4 years ago

The expression myBool!false?string('A', 'B') causes error

Caused by: freemarker.core._MiscTemplateException: Can't convert boolean to string automatically, because the "boolean_format" setting was "true,false", which is the legacy default computer-language format, and hence isn't accepted.

----
Tip: If you just want "true"/"false" result as you are generting computer-language output, use "?c", like ${myBool?c}.
----
Tip: You can write myBool?string('yes', 'no') and like to specify boolean formatting in place.
----
Tip: If you need the same two values on most places, the programmers should set the "boolean_format" setting to something like "yes,no".
----
sunmingtao commented 4 years ago

The !false part causes the problem. Removing it fixes it -- myBool?string('A', 'B')