[stringtemplate-interest] [Java] unrendering a template back to an object

Terence Parr parrt at cs.usfca.edu
Mon Feb 20 13:39:10 PST 2012


Hi,Unfortunately, ST is simply generating random text as far as it is concerned. It has no idea in what language is generating output nor which phrase within a particular language. This is almost certainly an undecidable problem.

Ter
On Feb 19, 2012, at 5:21 PM, Vivek Ramaswamy wrote:

> Hi Interest List,
> 
> Apologies if this is a newbie question but how do I take a string that
> I know is derived from a particular template and render it back to an
> object of the type that originally populated it?  If this solution (or
> known availability of one) is posted somewhere , I'd greatly
> appreciate an address.
> 
> Details below.
> 
> Kind regards,
> 
> VR
> 
> [1]  I have a class named Person:
> public class Person {
> String firstName;
> String lastName;
> public void getFirstName(){
>   return firstName;
> }
> public String getFirstName() {
>   return firstName;
> }
> }
> 
> [2]  I have a template person.stg:
> html(p):==<<
> <html>
>  <body>
>     <dl>
>            <dt>first name <dd>^p.firstName$</dd></dt>
>            <dt>last name <dd>^p.lastName$</dd></dt>
>     </dl>
>  </body>
> </html>
>>> 
> 
> [3]  I then render the template:
> 		Person person = new Person();
> 		person.setFirstName("Vivek");
> 		person.setLastName("Ramaswamy");
> 		STGroup g = new STGroupFile("templates/person/person.stg","^","$");
> 		ST st = g.getInstanceOf("html");
>                st.add("p",person);
>                String renderedTemplate = st.render();
> 
> [4]  My question, does StringTemplate give me the ability to take the
> String output, 'renderedTemplate', and unrender it back into a Person
> object?  In effect unmarshall it.  It seems like this might be
> possible if I provide the original template and a class definition.
> I'm guessing this is _not_ possible but I thought I'd check before
> building something that does this for my specific situation.
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest



More information about the stringtemplate-interest mailing list