Skip to content

Instantly share code, notes, and snippets.

@saka1029
Created June 22, 2015 22:15
Show Gist options
  • Save saka1029/f32f0b06d75d0bc49cc8 to your computer and use it in GitHub Desktop.
Save saka1029/f32f0b06d75d0bc49cc8 to your computer and use it in GitHub Desktop.
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
public class Main {
static final String JSON =
"{\n"
+ " asset: \n"
+ " {\n"
+ " 'name': name,\n"
+ " 'desc': {\n"
+ " 'country': country,\n"
+ " 'city': city,\n"
+ " 'postal': postal,\n"
+ " 'street': street,\n"
+ " 'substreet': substreet,\n"
+ " 'year': year,\n"
+ " 'sqm': sqm\n"
+ " },\n"
+ " 'owner': [owner],\n"
+ " 'manager': [manager],\n"
+ " 'lease': {\n"
+ " 'leasee': [\n"
+ " {\n"
+ " 'userId': leaseeId,\n"
+ " 'start': leaseeStart,\n"
+ " 'end': leaseeeEnd\n"
+ " }\n"
+ " ],\n"
+ " 'expire': leaseExpire,\n"
+ " 'percentIncrease': leasePercentIncrease,\n"
+ " 'dueDate': dueDate\n"
+ " },\n"
+ " 'deposit': {\n"
+ " 'bank': 'Sample Bank',\n"
+ " 'description': 'This is a bank'\n"
+ " }\n"
+ " }\n"
+ "}\n"
;
public static void main(String[] args) throws FileNotFoundException, IOException {
Gson gson = new Gson();
Root root = (Root)gson.fromJson(JSON, Root.class);
System.out.println(root);
String s = gson.toJson(root);
System.out.println(s);
}
static class Root {
private Asset asset;
}
static class Asset {
public String mId;
@SerializedName("name")
public String mName;
@SerializedName("desc")
public Map<String, Object> mDesc;
public String mCountry;
public String mCity;
public String mPostal;
public String mStreet;
public String mSubstreet;
public int mYear;
public int mSqm;
@SerializedName("owner")
public List<String> mOwners;
@SerializedName("manager")
public List<String> mManagers;
public int mPercentIncrease;
public int mDueDate;
public String mDepositBank;
public String mDepositDescription;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment