
// GenJSON.java
// Andrew Davison, ad@coe.psu.ac.th, July 2023

/* Format data as JSON using the "json.vm" template.
   Note: this does not require JsonTool, which is only
   used in UseJsonTool.java.

  Usage:
    > compile GenJSON.java
    > run GenJSON
*/

import java.io.*;
import java.util.*;

import org.apache.velocity.*;
import org.apache.velocity.app.*;


public class GenJSON
{
  private static final String TEMPLATE_FNM = "json.vm";


  public static void main(String[] args) throws Exception
  {
    Velocity.init();
    System.out.println("Loading template: " + TEMPLATE_FNM);
    Template template = Velocity.getTemplate(TEMPLATE_FNM);
     
    VelocityContext vc = new VelocityContext();
    vc.put("firstName", "Andrew");
    vc.put("lastName", "Davison");
    vc.put("street", "PSU");
    vc.put("city", "Hat Yai");
    vc.put("state", "Songkla");
    vc.put("country", "Thailand");
    vc.put("email","ad@coe.psu.ac.th");

    vc.put("roles", Arrays.asList("teacher","contributor"));

    // generate text using template
    StringWriter sw = new StringWriter();
    template.merge(vc, sw);
    System.out.println(sw);
  } /* main */

}  // end of GenJSON class

