src/main/java/io/magicthegathering/javasdk/api/MTGAPI.java
private static List<JsonObject> getJsonObject(String path, Gson deserializer) {
		String url = String.format("%s/%s", ENDPOINT, path);
		Request request = new Request.Builder().url(url).build();
		Response response;
		try {
			response = CLIENT.newCall(request).execute();

			ArrayList<JsonObject> objectList = new ArrayList<>();
			String linkHeader = response.headers().get("Link");
			if (linkHeader == null || linkHeader.isEmpty() || path.contains("page=")) {
				objectList.add(deserializer.fromJson(response.body()
						.string(), JsonObject.class));
				return objectList;
			} else {
				int numberOfPages = 0;
				String[] linkStrings = linkHeader.split(DELIM_LINK);
				List<String[]> paramList = new ArrayList<>();
				for (String link : linkStrings) {
					paramList.add(link.split(DELIM_LINK_PARAM));
				}
				for (String[] params : paramList) {
					if (params[1].contains("last")) {
						Matcher matcher = Pattern.compile("page=[0-9]+").matcher(params[0]);
						numberOfPages = (matcher.find()) ? Integer.parseInt(matcher.group().substring(5)) : 0;
					}
				}

				objectList.add(deserializer.fromJson(response.body().string(), JsonObject.class));

				if (!url.contains("?")) {
					url += "?";
				}

				for(int i = 1; i <= numberOfPages; i++){
					request = new Request.Builder().url(url + "&page=" + i).build();
					response = CLIENT.newCall(request).execute();
					objectList.add(deserializer.fromJson(response.body().string(), JsonObject.class));
				}

				return objectList;
			}
		} catch (IOException e) {
			throw new HttpRequestFailedException(e);
		}

	}
private static List<JsonObject> getJsonObject(String path, Gson deserializer) {
		String url = String.format("%s/%s", ENDPOINT, path);
		Request request = new Request.Builder().url(url).build();
		Response response;
		try {
			response = CLIENT.newCall(request).execute();

			ArrayList<JsonObject> objectList = new ArrayList<>();
			String linkHeader = response.headers().get("Link");
			if (linkHeader == null || linkHeader.isEmpty() || path.contains("page=")) {
				objectList.add(deserializer.fromJson(response.body()
						.string(), JsonObject.class));
				return objectList;
			} else {
				int numberOfPages = 0;
				String[] linkStrings = linkHeader.split(DELIM_LINK);
				List<String[]> paramList = new ArrayList<>();
				for (String link : linkStrings) {
					paramList.add(link.split(DELIM_LINK_PARAM));
				}
				for (String[] params : paramList) {
					if (params[1].contains("last")) {
						Matcher matcher = Pattern.compile("page=[0-9]+").matcher(params[0]);
						numberOfPages = (matcher.find()) ? Integer.parseInt(matcher.group().substring(5)) : 0;
					}
				}

				objectList.add(deserializer.fromJson(response.body().string(), JsonObject.class));

				if (!url.contains("?")) {
					url += "?";
				}

				for(int i = 1; i <= numberOfPages; i++){
					request = new Request.Builder().url(url + "&page=" + i).build();
					response = CLIENT.newCall(request).execute();
					objectList.add(deserializer.fromJson(response.body().string(), JsonObject.class));
				}

				return objectList;
			}
		} catch (IOException e) {
			throw new HttpRequestFailedException(e);
		}

	}
private static List < JsonObject > getJsonObject ( String path , Gson deserializer ) { String url = String . format ( "%s/%s" , ENDPOINT , path ) ; Request request = new Request . Builder ( ) . url ( url ) . build ( ) ; Response response ; try { response = CLIENT . newCall ( request ) . execute ( ) ; ArrayList < JsonObject > objectList = new ArrayList <> ( ) ; String linkHeader = response . headers ( ) . get ( "Link" ) ; if ( linkHeader == null || linkHeader . isEmpty ( ) || path . contains ( "page=" ) ) { objectList . add ( deserializer . fromJson ( response . body ( ) . string ( ) , JsonObject . class ) ) ; return objectList ; } else { int numberOfPages = 0 ; String [ ] linkStrings = linkHeader . split ( DELIM_LINK ) ; List < String [ ] > paramList = new ArrayList <> ( ) ; for ( String link : linkStrings ) { paramList . add ( link . split ( DELIM_LINK_PARAM ) ) ; } for ( String [ ] params : paramList ) { if ( params [ 1 ] . contains ( "last" ) ) { Matcher matcher = Pattern . compile ( "page=[0-9]+" ) . matcher ( params [ 0 ] ) ; numberOfPages = ( matcher . find ( ) ) ? Integer . parseInt ( matcher . group ( ) . substring ( 5 ) ) : 0 ; } } objectList . add ( deserializer . fromJson ( response . body ( ) . string ( ) , JsonObject . class ) ) ; if ( ! url . contains ( "?" ) ) { url += "?" ; } for ( int i = 1 ; i <= numberOfPages ; i ++ ) { request = new Request . Builder ( ) . url ( url + "&page=" + i ) . build ( ) ; response = CLIENT . newCall ( request ) . execute ( ) ; objectList . add ( deserializer . fromJson ( response . body ( ) . string ( ) , JsonObject . class ) ) ; } return objectList ; } } catch ( IOException e ) { throw new HttpRequestFailedException ( e ) ; } }
Deserialize the object to the type expected.

@param path Controlled by what is calling the function, currently "sets" or "cards"
depending on the calling class.
@param deserializer {@link Gson} object that will be used to deserialize the JSON returned
from the web API.
@return The parsed {@link JsonObject}
Deserialize the object to the type expected .