Skip to content

Instantly share code, notes, and snippets.

@butaji
Last active August 29, 2015 14:10
Show Gist options
  • Save butaji/b322d48cf937bcd51c30 to your computer and use it in GitHub Desktop.
Save butaji/b322d48cf937bcd51c30 to your computer and use it in GitHub Desktop.
Serialize JSON to Map through GSON
import java.lang.reflect.Type;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
public class App {
public static void main(String[] args) {
String jsons = "{'appname':'Remoto', 'Version':'2.1', 'UUID':'agbd'}";
Type type = new TypeToken<Map<String, String>>(){}.getType();
Map<String, String> parsed = new Gson().fromJson(jsons, type);
System.out.println(parsed);
}
}
@butaji
Copy link
Author

butaji commented Dec 1, 2014

Run as
javac -cp ".:gson-2.2.4.jar" App.java && java -cp ".:gson-2.2.4.jar" App

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment