Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for LoganSquare #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions JsonToJava-Lib/src/com/jsontojava/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@ public class Main {
private static final String OPTION_PARCELABLE = "p";



// /**
// * @param args
// * @throws IOException
// */
// public static void main(String[] args) throws IOException {
//
// JsonToJava jsonToJava = new JsonToJava();
//
//
//
// jsonToJava.setUrl("http://pastebin.com/raw/LxguVT6c");
// jsonToJava.setPackage("me.pushapp.bito.model");
// jsonToJava.setBaseType("User");
// jsonToJava.addOutputOption(OutputOption.LOGANSQUARE);
// jsonToJava.addOutputOption(OutputOption.GSON);
// jsonToJava.addOutputOption(OutputOption.PARCELABLE);
// jsonToJava.addOutputOption(OutputOption.TO_STRING);
//
// jsonToJava.fetchJson();
// FileOutputStream outputStream = new FileOutputStream(jsonToJava.getPackage() + ".zip");
// jsonToJava.outputZipFile(outputStream);
//
//
// }

// /**
// * @param args
// * @throws IOException
Expand Down
15 changes: 15 additions & 0 deletions JsonToJava-Lib/src/com/jsontojava/NewType.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public class NewType {
public static final String IMPORT_ANDROID_OS_PARCELABLE = "android.os.Parcelable";
public static final String IMPORT_ANDROID_OS_PARCEL = "android.os.Parcel";
public static final String IMPORT_GSON_SERIALIZED_NAME = "com.google.gson.annotations.SerializedName";
public static final String IMPORT_LOGANSQUARE_OBJECT = "com.bluelinelabs.logansquare.annotation.JsonObject";
public static final String IMPORT_LOGANSQUARE_FIELD = "com.bluelinelabs.logansquare.annotation.JsonField";



public String name;
public String pack;
public Set<String> imports;
Expand Down Expand Up @@ -132,13 +137,20 @@ public String toPojoString(EnumSet<OutputOption> options,JsonToJava jsonToJava)
if (options.contains(OutputOption.GSON)) {
imports.add(IMPORT_GSON_SERIALIZED_NAME);
}
if (options.contains(OutputOption.LOGANSQUARE)){
imports.add(IMPORT_LOGANSQUARE_FIELD);
imports.add(IMPORT_LOGANSQUARE_OBJECT);
}
StringBuilder sBuilder = new StringBuilder();

sBuilder.append("package ").append(pack).append(";\n\n");
for (String s : imports) {
sBuilder.append("import ").append(s).append(";\n");
}
sBuilder.append("\n\n");
if (options.contains(OutputOption.LOGANSQUARE))
sBuilder.append("@JsonObject\n");

sBuilder.append("public class ").append(name);
if (options.contains(OutputOption.PARCELABLE)) {
sBuilder.append(" implements Parcelable");
Expand All @@ -161,6 +173,9 @@ public String toPojoString(EnumSet<OutputOption> options,JsonToJava jsonToJava)
if (options.contains(OutputOption.GSON)) {
sBuilder.append(ONE_TAB+"@SerializedName(" + member.getFieldName() + ")\n");
}
if (options.contains(OutputOption.LOGANSQUARE)) {
sBuilder.append(ONE_TAB+"@JsonField(name = " + member.getFieldName() + ")\n");
}
sBuilder.append(ONE_TAB+"private " + member.getType() + " " + member.getName() + ";").append("\n");
}
sBuilder.append("\n\n");
Expand Down
2 changes: 1 addition & 1 deletion JsonToJava-Lib/src/com/jsontojava/OutputOption.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.jsontojava;

public enum OutputOption {
PARCELABLE,GSON,JACKSON,ORG_JSON,GREEN_DAO,CONTENT_PROVIDER,RETROFIT,TO_STRING
PARCELABLE,GSON,JACKSON,ORG_JSON,GREEN_DAO,CONTENT_PROVIDER,RETROFIT,TO_STRING,LOGANSQUARE

}