Example usage for com.google.gson.reflect TypeToken TypeToken

List of usage examples for com.google.gson.reflect TypeToken TypeToken

Introduction

In this page you can find the example usage for com.google.gson.reflect TypeToken TypeToken.

Prototype

@SuppressWarnings("unchecked")
protected TypeToken() 

Source Link

Document

Constructs a new type literal.

Usage

From source file:Clients.ClientThread.java

public List<FoodData> getFood(String category) throws IOException {
    out.println("{\"method\":" + "\"getFood\"" + ",\"params\":[\"" + category + "\"]}");
    String response = in.readLine();
    //JOptionPane.showMessageDialog(null, response);
    Gson gson = new Gson();
    return gson.fromJson(response, new TypeToken<List<FoodData>>() {
    }.getType());// w ww .jav a 2s . c o m
}

From source file:Clients.ClientThread.java

public List<FoodData> getAllFood() throws IOException {
    out.println("{\"method\":" + "\"getAllFood\"" + ",\"params\":[]}");
    String response = in.readLine();
    //JOptionPane.showMessageDialog(null, response);
    Gson gson = new Gson();
    return gson.fromJson(response, new TypeToken<List<FoodData>>() {
    }.getType());/*w w w.  j  a  va 2s  .c  om*/
}

From source file:Clients.ClientThread.java

public Iterable<FoodData> getOrder(int tableNumber) throws IOException {
    out.println("{\"method\":" + "\"getOrder\"" + ",\"params\":[" + tableNumber + "]}");
    String response = in.readLine();
    //JOptionPane.showMessageDialog(null, response);
    if (response.equals("null"))
        return new ArrayList<FoodData>();
    Gson gson = new Gson();
    return gson.fromJson(response, new TypeToken<List<FoodData>>() {
    }.getType());//  ww w .j  a  va2s  .c  om
}

From source file:cloud.artik.api.DevicesApi.java

License:Apache License

/**
 * Add Device//from   w  w  w. ja  v  a2 s. c o m
 * Create a device
 * @param device Device to be added to the user (required)
 * @return ApiResponse&lt;DeviceEnvelope&gt;
 * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
 */
public ApiResponse<DeviceEnvelope> addDeviceWithHttpInfo(Device device) throws ApiException {
    com.squareup.okhttp.Call call = addDeviceCall(device, null, null);
    Type localVarReturnType = new TypeToken<DeviceEnvelope>() {
    }.getType();
    return apiClient.execute(call, localVarReturnType);
}

From source file:cloud.artik.api.DevicesApi.java

License:Apache License

/**
 * Add Device (asynchronously)/*from www . ja  v  a 2 s. c  o  m*/
 * Create a device
 * @param device Device to be added to the user (required)
 * @param callback The callback to be executed when the API call finishes
 * @return The request call
 * @throws ApiException If fail to process the API call, e.g. serializing the request body object
 */
public com.squareup.okhttp.Call addDeviceAsync(Device device, final ApiCallback<DeviceEnvelope> callback)
        throws ApiException {

    ProgressResponseBody.ProgressListener progressListener = null;
    ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

    if (callback != null) {
        progressListener = new ProgressResponseBody.ProgressListener() {
            @Override
            public void update(long bytesRead, long contentLength, boolean done) {
                callback.onDownloadProgress(bytesRead, contentLength, done);
            }
        };

        progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
            @Override
            public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
                callback.onUploadProgress(bytesWritten, contentLength, done);
            }
        };
    }

    com.squareup.okhttp.Call call = addDeviceCall(device, progressListener, progressRequestListener);
    Type localVarReturnType = new TypeToken<DeviceEnvelope>() {
    }.getType();
    apiClient.executeAsync(call, localVarReturnType, callback);
    return call;
}

From source file:cloud.artik.api.DevicesApi.java

License:Apache License

/**
 * Delete Device/*w  ww.  j ava 2 s  .  co  m*/
 * Deletes a device
 * @param deviceId deviceId (required)
 * @return ApiResponse&lt;DeviceEnvelope&gt;
 * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
 */
public ApiResponse<DeviceEnvelope> deleteDeviceWithHttpInfo(String deviceId) throws ApiException {
    com.squareup.okhttp.Call call = deleteDeviceCall(deviceId, null, null);
    Type localVarReturnType = new TypeToken<DeviceEnvelope>() {
    }.getType();
    return apiClient.execute(call, localVarReturnType);
}

From source file:cloud.artik.api.DevicesApi.java

License:Apache License

/**
 * Delete Device (asynchronously)/*from   w w w  .  ja v  a 2  s  . c o m*/
 * Deletes a device
 * @param deviceId deviceId (required)
 * @param callback The callback to be executed when the API call finishes
 * @return The request call
 * @throws ApiException If fail to process the API call, e.g. serializing the request body object
 */
public com.squareup.okhttp.Call deleteDeviceAsync(String deviceId, final ApiCallback<DeviceEnvelope> callback)
        throws ApiException {

    ProgressResponseBody.ProgressListener progressListener = null;
    ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

    if (callback != null) {
        progressListener = new ProgressResponseBody.ProgressListener() {
            @Override
            public void update(long bytesRead, long contentLength, boolean done) {
                callback.onDownloadProgress(bytesRead, contentLength, done);
            }
        };

        progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
            @Override
            public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
                callback.onUploadProgress(bytesWritten, contentLength, done);
            }
        };
    }

    com.squareup.okhttp.Call call = deleteDeviceCall(deviceId, progressListener, progressRequestListener);
    Type localVarReturnType = new TypeToken<DeviceEnvelope>() {
    }.getType();
    apiClient.executeAsync(call, localVarReturnType, callback);
    return call;
}

From source file:cloud.artik.api.DevicesApi.java

License:Apache License

/**
 * Delete Device Token//from  ww  w.j a v a  2 s  . c  om
 * Deletes a device&#39;s token
 * @param deviceId deviceId (required)
 * @return ApiResponse&lt;DeviceTokenEnvelope&gt;
 * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
 */
public ApiResponse<DeviceTokenEnvelope> deleteDeviceTokenWithHttpInfo(String deviceId) throws ApiException {
    com.squareup.okhttp.Call call = deleteDeviceTokenCall(deviceId, null, null);
    Type localVarReturnType = new TypeToken<DeviceTokenEnvelope>() {
    }.getType();
    return apiClient.execute(call, localVarReturnType);
}

From source file:cloud.artik.api.DevicesApi.java

License:Apache License

/**
 * Delete Device Token (asynchronously)// w w w .j av  a2s  .  c  om
 * Deletes a device&#39;s token
 * @param deviceId deviceId (required)
 * @param callback The callback to be executed when the API call finishes
 * @return The request call
 * @throws ApiException If fail to process the API call, e.g. serializing the request body object
 */
public com.squareup.okhttp.Call deleteDeviceTokenAsync(String deviceId,
        final ApiCallback<DeviceTokenEnvelope> callback) throws ApiException {

    ProgressResponseBody.ProgressListener progressListener = null;
    ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

    if (callback != null) {
        progressListener = new ProgressResponseBody.ProgressListener() {
            @Override
            public void update(long bytesRead, long contentLength, boolean done) {
                callback.onDownloadProgress(bytesRead, contentLength, done);
            }
        };

        progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
            @Override
            public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
                callback.onUploadProgress(bytesWritten, contentLength, done);
            }
        };
    }

    com.squareup.okhttp.Call call = deleteDeviceTokenCall(deviceId, progressListener, progressRequestListener);
    Type localVarReturnType = new TypeToken<DeviceTokenEnvelope>() {
    }.getType();
    apiClient.executeAsync(call, localVarReturnType, callback);
    return call;
}

From source file:cloud.artik.api.DevicesApi.java

License:Apache License

/**
 * Get Device// w  ww  .  j  a  v  a2  s . c o m
 * Retrieves a device
 * @param deviceId deviceId (required)
 * @return ApiResponse&lt;DeviceEnvelope&gt;
 * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
 */
public ApiResponse<DeviceEnvelope> getDeviceWithHttpInfo(String deviceId) throws ApiException {
    com.squareup.okhttp.Call call = getDeviceCall(deviceId, null, null);
    Type localVarReturnType = new TypeToken<DeviceEnvelope>() {
    }.getType();
    return apiClient.execute(call, localVarReturnType);
}