Mustache to JSON object

428 views
Skip to first unread message

Josh Unger

unread,
Jan 16, 2014, 11:24:07 AM1/16/14
to mustac...@googlegroups.com
Sam -

Can you share a code snippet where you're executing a mustache template with a writer and then serializing it as a JSON object?  I understanding the general idea, but I'd like to see your snippet and see if you're using a JSON library that supports a writer.

Thanks.

-josh

Sam Pullara

unread,
Jan 16, 2014, 10:14:04 PM1/16/14
to mustac...@googlegroups.com
I can probably post some code later, but the gist is that you pass Mustache a StringWriter and then use Jackson or another json library to return it as a value, something like:

{ “html”: “<html>…</html>”}

Where the <html> value is just StringWriter.toString().

Sam

--
You received this message because you are subscribed to the Google Groups "mustache.java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mustachejava...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Josh Unger

unread,
Jan 16, 2014, 10:30:09 PM1/16/14
to mustac...@googlegroups.com
That is all I needed.  I wasn't sure if you had written a writer that would automatically escape json content (if that makes sense).

Thanks.

-josh

Sam Pullara

unread,
Jan 16, 2014, 10:33:26 PM1/16/14
to mustachejava
Nope, I let Jackson do that part of it. 

Sam

---
Sent from Boxer | http://getboxer.com

Josh Unger

unread,
Jan 17, 2014, 10:38:23 AM1/17/14
to mustac...@googlegroups.com
I wasn't sure if this would be better... ?

public JSONStringWriter extends Writer
{
    @Override
    public void write(...)
    {
        // escape strings
        // write to the underlying writer
    }
}

mustache.execute(jsonwriter, view);

?

Thanks.

-josh
Reply all
Reply to author
Forward
0 new messages