Created
November 18, 2015 08:19
-
-
Save DavidMihola/2ee7740a2c0c22b016b4 to your computer and use it in GitHub Desktop.
Revisions
-
DavidMihola created this gist
Nov 18, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,190 @@ package com.example; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import java.util.List; /** * Created by dmta on 18.11.15. */ public class GsonChallongeTest { private static final String JSON = "[\n" + " {\n" + " \"participant\": {\n" + " \"active\": true,\n" + " \"checked_in_at\": null,\n" + " \"created_at\": \"2015-01-19T16:54:40-05:00\",\n" + " \"final_rank\": null,\n" + " \"group_id\": null,\n" + " \"icon\": null,\n" + " \"id\": 16543993,\n" + " \"invitation_id\": null,\n" + " \"invite_email\": null,\n" + " \"misc\": null,\n" + " \"name\": \"Participant #1\",\n" + " \"on_waiting_list\": false,\n" + " \"seed\": 1,\n" + " \"tournament_id\": 1086875,\n" + " \"updated_at\": \"2015-01-19T16:54:40-05:00\",\n" + " \"challonge_username\": null,\n" + " \"challonge_email_address_verified\": null,\n" + " \"removable\": true,\n" + " \"participatable_or_invitation_attached\": false,\n" + " \"confirm_remove\": true,\n" + " \"invitation_pending\": false,\n" + " \"display_name_with_invitation_email_address\": \"Participant #1\",\n" + " \"email_hash\": null,\n" + " \"username\": null,\n" + " \"attached_participatable_portrait_url\": null,\n" + " \"can_check_in\": false,\n" + " \"checked_in\": false,\n" + " \"reactivatable\": false\n" + " }\n" + " },\n" + " {\n" + " \"participant\": {\n" + " \"active\": true,\n" + " \"checked_in_at\": null,\n" + " \"created_at\": \"2015-01-19T16:54:43-05:00\",\n" + " \"final_rank\": null,\n" + " \"group_id\": null,\n" + " \"icon\": null,\n" + " \"id\": 16543994,\n" + " \"invitation_id\": null,\n" + " \"invite_email\": null,\n" + " \"misc\": null,\n" + " \"name\": \"Participant #2\",\n" + " \"on_waiting_list\": false,\n" + " \"seed\": 2,\n" + " \"tournament_id\": 1086875,\n" + " \"updated_at\": \"2015-01-19T16:54:43-05:00\",\n" + " \"challonge_username\": null,\n" + " \"challonge_email_address_verified\": null,\n" + " \"removable\": true,\n" + " \"participatable_or_invitation_attached\": false,\n" + " \"confirm_remove\": true,\n" + " \"invitation_pending\": false,\n" + " \"display_name_with_invitation_email_address\": \"Participant #2\",\n" + " \"email_hash\": null,\n" + " \"username\": null,\n" + " \"attached_participatable_portrait_url\": null,\n" + " \"can_check_in\": false,\n" + " \"checked_in\": false,\n" + " \"reactivatable\": false\n" + " }\n" + " },\n" + " {\n" + " \"participant\": {\n" + " \"active\": true,\n" + " \"checked_in_at\": null,\n" + " \"created_at\": \"2015-01-19T16:57:10-05:00\",\n" + " \"final_rank\": null,\n" + " \"group_id\": null,\n" + " \"icon\": null,\n" + " \"id\": 16543996,\n" + " \"invitation_id\": null,\n" + " \"invite_email\": null,\n" + " \"misc\": null,\n" + " \"name\": \"Participant #3\",\n" + " \"on_waiting_list\": false,\n" + " \"seed\": 3,\n" + " \"tournament_id\": 1086875,\n" + " \"updated_at\": \"2015-01-19T16:57:10-05:00\",\n" + " \"challonge_username\": null,\n" + " \"challonge_email_address_verified\": null,\n" + " \"removable\": true,\n" + " \"participatable_or_invitation_attached\": false,\n" + " \"confirm_remove\": true,\n" + " \"invitation_pending\": false,\n" + " \"display_name_with_invitation_email_address\": \"Participant #3\",\n" + " \"email_hash\": null,\n" + " \"username\": null,\n" + " \"attached_participatable_portrait_url\": null,\n" + " \"can_check_in\": false,\n" + " \"checked_in\": false,\n" + " \"reactivatable\": false\n" + " }\n" + " },\n" + " {\n" + " \"participant\": {\n" + " \"active\": true,\n" + " \"checked_in_at\": null,\n" + " \"created_at\": \"2015-01-19T16:57:12-05:00\",\n" + " \"final_rank\": null,\n" + " \"group_id\": null,\n" + " \"icon\": null,\n" + " \"id\": 16543997,\n" + " \"invitation_id\": null,\n" + " \"invite_email\": null,\n" + " \"misc\": null,\n" + " \"name\": \"Participant #4\",\n" + " \"on_waiting_list\": false,\n" + " \"seed\": 4,\n" + " \"tournament_id\": 1086875,\n" + " \"updated_at\": \"2015-01-19T16:57:12-05:00\",\n" + " \"challonge_username\": null,\n" + " \"challonge_email_address_verified\": null,\n" + " \"removable\": true,\n" + " \"participatable_or_invitation_attached\": false,\n" + " \"confirm_remove\": true,\n" + " \"invitation_pending\": false,\n" + " \"display_name_with_invitation_email_address\": \"Participant #4\",\n" + " \"email_hash\": null,\n" + " \"username\": null,\n" + " \"attached_participatable_portrait_url\": null,\n" + " \"can_check_in\": false,\n" + " \"checked_in\": false,\n" + " \"reactivatable\": false\n" + " }\n" + " }\n" + "]"; public static void main(String[] args) { List<ParticipantWrapper> list = new Gson().fromJson(JSON, new TypeToken<List<ParticipantWrapper>>() { }.getType()); System.out.println(list); // prints: // ParticipantWrapper{participant=Participant{id='16543993', name='Participant #1'}}, ParticipantWrapper{participant=Participant{id='16543994', name='Participant #2'}}, ParticipantWrapper{participant=Participant{id='16543996', name='Participant #3'}}, ParticipantWrapper{participant=Participant{id='16543997', name='Participant #4'}}] } public static class Participant { private String id; private String name; public String getPlayerId() { return id; } public String getPlayerName() { return name; } @Override public String toString() { return "Participant{" + "id='" + id + '\'' + ", name='" + name + '\'' + '}'; } } public class ParticipantWrapper { public final Participant participant; public ParticipantWrapper() { participant = null; } @Override public String toString() { return "ParticipantWrapper{" + "participant=" + participant + '}'; } } }