com.nu.art.http.Transaction_JSON Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http-module Show documentation
Show all versions of http-module Show documentation
A collection of core tools I use
package com.nu.art.http;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.nu.art.http.HttpModule.BaseTransaction;
/**
* Created by TacB0sS on 16-Sep 2017.
*/
public class Transaction_JSON
extends BaseTransaction {
public static final Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
@Override
protected IHttpRequest createRequest() {
return super.createRequest().addHeader("Content-Type", "application/json");
}
protected IHttpRequest createPlainRequest() {
return super.createRequest();
}
public static abstract class JsonHttpResponseListener
extends HttpResponseListener {
protected JsonHttpResponseListener(Class responseType) {
super(responseType, String.class);
}
@Override
protected Type deserialize(Class type, String responseAsString) {
return gson.fromJson(responseAsString, type);
}
@Override
public void onError(HttpResponse httpResponse, String errorAsString) {
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy