com.sailthru.client.handler.JsonHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sailthru-java-client Show documentation
Show all versions of sailthru-java-client Show documentation
Java client library for Sailthru API
The newest version!
package com.sailthru.client.handler;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.sailthru.client.SailthruUtil;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
/**
* handles JSON response from server
*
* @author Prajwal Tuladhar
*/
public class JsonHandler implements SailthruResponseHandler {
public static final String format = "json";
public Object parseResponse(String response) {
GsonBuilder builder = new GsonBuilder();
builder.setDateFormat(SailthruUtil.SAILTHRU_API_DATE_FORMAT);
builder.registerTypeAdapter(Object.class, new NaturalDeserializer());
Gson gson = builder.create();
return gson.fromJson(response, Object.class);
}
public String getFormat() {
return format;
}
// http://stackoverflow.com/questions/2779251/convert-json-to-hashmap-using-gson-in-java/4799594#4799594
//Will get rid of this at some point
class NaturalDeserializer implements JsonDeserializer
© 2015 - 2025 Weber Informatics LLC | Privacy Policy