package com.nbusy.app.dummy;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Logger;

/**
 * Created by teoman.soygul on 6/2/2014.
 */
public class JsonClient {
    public String getJSON(String url, int timeout) {
        try {
            URL u = new URL(url);
            HttpURLConnection c = (HttpURLConnection) u.openConnection();
            c.setRequestMethod("GET");
            c.setRequestProperty("Content-length", "0");
            c.setUseCaches(false);
            c.setAllowUserInteraction(false);
            c.setConnectTimeout(timeout);
            c.setReadTimeout(timeout);
            c.connect();
            int status = c.getResponseCode();

            switch (status) {
                case 200:
                case 201:
                    BufferedReader reader = new BufferedReader(new InputStreamReader(c.getInputStream()));
                    StringBuilder response = new StringBuilder();
                    String line;
                    while ((line = reader.readLine()) != null) {
                        response.append(line+"\n");
                    }
                    reader.close();
                    return response.toString();
            }

        } catch (MalformedURLException ex) {
            //Logger.getLogger(DebugServer.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            //Logger.getLogger(DebugServer.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}

@@ -25,16 +25,48 @@
 mmy;%0D%0A%0D%0A
+import com.google.gson.Gson;%0D%0A%0D%0A
 import j
@@ -299,44 +299,53 @@
 %0A * 
-Created by teoman.soygul on 6/2/2014
+HTTP client with JSON content type by default
 .%0D%0A 
@@ -386,22 +386,21 @@
  public 
-String
+%3CT%3E T
  getJSON
@@ -423,16 +423,45 @@
  timeout
+, java.lang.Class%3CT%3E classOfT
 ) %7B%0D%0A   
@@ -1418,34 +1418,140 @@
     
-return response.toString()
+Gson gson = new Gson();%0D%0A                    T data = gson.fromJson(response.toString(), classOfT);%0D%0A                    return data
 ;%0D%0A 

fix json client