This repository has been archived by the owner on May 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#14 Json parsing moved to separate class
- Loading branch information
Showing
2 changed files
with
26 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
23 changes: 23 additions & 0 deletions
23
api-sdk/src/main/java/com/smartling/api/sdk/JsonReader.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.smartling.api.sdk; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.reflect.TypeToken; | ||
import com.smartling.api.sdk.dto.ApiResponse; | ||
import com.smartling.api.sdk.dto.ApiResponseWrapper; | ||
import com.smartling.api.sdk.dto.Data; | ||
import com.smartling.api.sdk.util.DateTypeAdapter; | ||
|
||
import java.util.Date; | ||
|
||
public class JsonReader { | ||
public static <T extends Data> ApiResponse<T> getApiResponse(String response, TypeToken<ApiResponseWrapper<T>> responseType) { | ||
final GsonBuilder builder = new GsonBuilder(); | ||
builder.registerTypeAdapter(Date.class, new DateTypeAdapter()); | ||
|
||
final Gson gson = builder.create(); | ||
final ApiResponseWrapper<T> responseWrapper = gson.fromJson(response, responseType.getType()); | ||
|
||
return responseWrapper.getResponse(); | ||
} | ||
} |