Package com.jsontojava

Examples of com.jsontojava.JsonToJava


@SuppressWarnings("serial")
public class JsonToJavaServlet extends HttpServlet {
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {

    JsonToJava jsonToJava = new JsonToJava();
    jsonToJava.setUrl(req.getParameter("url"));
    jsonToJava.setPackage(req.getParameter("package"));
    jsonToJava.setBaseType(req.getParameter("class"));
    String[] options = req.getParameterValues("options");
    if(options != null){
    for(String option:options){
      jsonToJava.addOutputOption(OutputOption.valueOf(option));
    }
    }
    System.out.println(options);
    jsonToJava.fetchJson();
    ByteArrayOutputStream out = (ByteArrayOutputStream) jsonToJava
        .outputZipFile(new ByteArrayOutputStream());
    byte[] data = out.toByteArray();
    resp.setContentType("application/zip");
    resp.setContentLength(data.length);
    resp.setHeader("Content-Disposition",
        "inline; filename=" + jsonToJava.getPackage() + ".zip");
    resp.getOutputStream().write(data);
  }
View Full Code Here


  public static void main(String[] args) throws IOException, ParseException {
    Options options = createOptions();
   
    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse( options, args);
    JsonToJava jsonToJava = new JsonToJava();
   
    jsonToJava.setUrl(cmd.getOptionValue(OPTION_URL));
    jsonToJava.setPackage(cmd.getOptionValue(OPTION_PACKAGE));
    jsonToJava.setBaseType(cmd.getOptionValue(OPTION_ROOT));
    if(cmd.hasOption(OPTION_GSON)){
      jsonToJava.addOutputOption(OutputOption.GSON);
    }
    if(cmd.hasOption(OPTION_PARCELABLE)){
      jsonToJava.addOutputOption(OutputOption.PARCELABLE);
    }
    if(cmd.hasOption(OPTION_TO_STRING)){
      jsonToJava.addOutputOption(OutputOption.TO_STRING);
    }
   
    jsonToJava.fetchJson();
    File zipFile = new File(jsonToJava.getPackage() + ".zip");
    OutputStream os = new FileOutputStream(zipFile);
    jsonToJava.outputZipFile(os);
    os.close();
    System.out.println("\nFinished creating java classes.  Your files are located in " + zipFile.getAbsolutePath() );


 
View Full Code Here

TOP

Related Classes of com.jsontojava.JsonToJava

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.