-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for rendering non primitive types. #5
Comments
Good point. Some kind of white-list should be good. We need to design the way to specify such list and share it between set of templates... Besides, you should probably never render java.util.Date ... |
java.util.Date is just a bad example. |
Any suggestions about a way to specify toString-white-list? |
How about this: @GenerateRenderableAdapter( |
Yes, but this doesn't address sharing problem. We probably want to define per project list of classes, probably per java package list of classes... |
Ok, we can use package level annotation to define list of classes to render on package level: @RenderableClassList({ and we can define additional classes on class level: @GenerateRenderableAdapter( or even override it: @GenerateRenderableAdapter( |
I'm considering something like this: User.java:
MyList.java:
ClassList annotation can be reused in many other contexts later. |
Another concern is that we need a good default list of classes. Ideally it must be complete for JDK, and this seems not so trivial work... We shouldn't unexpectedly add new classes to default list We can sometime add some classes, but ideally it should happen only when we switch JDK version and new JDK version introduces some new classes, like |
I know this issue is an ancient issue but I think a better solution is to make static-mustache => static-handlebars. Handlebars is an extension of mustache that has helper functions (and a few other things). Thus the above rendering of nontrivial data types could be solved with handlebar helper functions. This would be especially useful for cases like dates and internationalization. However this is a massive undertaking as essentially you need to replace the parser with a handelbars parser. However there is a handlebars java (handlebars.java) parser so you could leverage that to build the AST instead of the current parser. Maybe someday I'll fork this project when I have time to see how much is required to get the handlebars.java parser to work with what is already present. |
According to readme: "Any boxed or unboxed primitive type is rendered with toString method. Strings are rendered as is. Rendering of other Java-types as mustache-variable is compile-time error.".
It makes difficult to render java.util.Date or java.util.UUID or java.net.URI values.
Maybe it would be better to have an option to specify classes, which values should be rendered using overloaded Object.toString() method.
Or it would be helpful to have a sort of guide for dealing with such cases.
The text was updated successfully, but these errors were encountered: