Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
88 lines (64 loc) · 2.8 KB

File metadata and controls

88 lines (64 loc) · 2.8 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.jsontojava.cli;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import com.jsontojava.JsonToJava;
import com.jsontojava.OutputOption;
public class Main {
private static final String OPTION_PACKAGE = "package";
private static final String OPTION_URL = "url";
private static final String OPTION_ROOT = "class";
private static final String OPTION_GSON = "g";
private static final String OPTION_PARCELABLE = "p";
private static final String OPTION_TO_STRING = "s";
/**
* @param args
* @throws IOException
* @throws ParseException
*/
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() );
}
private static Options createOptions(){
Options options = new Options();
options.addOption(OPTION_PARCELABLE, false, "Enabled implementation of Parcelable for all classes generated");
options.addOption(OPTION_GSON,false,"Enables Gson annotations");
options.addOption(OPTION_TO_STRING, false, "Enables overriding the toString method for new classes");
Option rootClass = OptionBuilder.hasArg().isRequired().withDescription("The name of the root class of the feed you are parsing").create(OPTION_ROOT);
options.addOption(rootClass);
Option url = OptionBuilder.hasArg().isRequired().withDescription("The url of the json feed you want to parse").create(OPTION_URL);
options.addOption(url);
Option pack = OptionBuilder.hasArg().isRequired().withDescription("The package name for the generated classes").create(OPTION_PACKAGE);
options.addOption(pack);
return options;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.