Support for direct interpolation of bytes into template output
My specific use case is that my HTML template is to include a large JSON string. What I'd like to be able to do, is inject this into my template as UTF-8 bytes instead of as a String. This is purely for performance as it will reduce object churn by allowing direct usage of the bytes produced by the JSON encoder I am using (i.e. Jackson) instead of turning the bytes into a String, just to be turned back into bytes.
Besides the syntax/construct used to denote that a value being interpolated into the output should be treated as bytes, I can see that there's a safety issue here of encoding alignment. I don't have any ideas on how to resolve that beyond putting the responsibility of the user of this construct to ensure that the given bytes are encoded using the same output encoding as the template.
Rocker doesn't support raw bytes for output. I suspect it would be output by getting cast as an Object and then have its .toString() method called for output in the current Rocker version. I don't think its a bad feature to allow for this type of optimization.
One feature I had thought of awhile ago was allowing type extensions to participate more directly with the rendering process. For example, allow one to pass a type that implements a "Renderable" interface that would allow that type to handle the rendering of itself directly to the RockerOutput. A standard type of something like a ByteArrayRenderable could then wrap a byte array and directly render itself. It would also clearly enforce the idea the caller knows what they are doing as well. You could then even do a JacksonRenderable (maybe making the charset matching irrelevant).
For example, allow one to pass a type that implements a "Renderable" interface that would allow that type to handle the rendering of itself directly to the RockerOutput.
That would do it. The method of Renderable that does the rendering could take a Charset parameter and either use it or fail if it can't.