Last active
August 29, 2015 14:10
-
-
Save butaji/b322d48cf937bcd51c30 to your computer and use it in GitHub Desktop.
Serialize JSON to Map through GSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run as
javac -cp ".:gson-2.2.4.jar" App.java && java -cp ".:gson-2.2.4.jar" App