add GsonRequest.body
This commit is contained in:
@ -7,6 +7,7 @@ import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import org.apache.hc.client5.http.fluent.Request;
|
||||
import org.apache.hc.core5.http.ContentType;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -45,6 +46,11 @@ public class GsonRequest extends CommonRequest {
|
||||
return this;
|
||||
}
|
||||
|
||||
public GsonRequest body(Object object) {
|
||||
request.bodyString(getGson().toJson(object), ContentType.APPLICATION_JSON);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> T resultAs(Class<T> clazz) throws IOException {
|
||||
return getGson().fromJson(super.asString(), clazz);
|
||||
}
|
||||
|
||||
@ -28,6 +28,12 @@ public class TimiRequest extends GsonRequest {
|
||||
return new TimiRequest(Request.post(url));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimiRequest body(Object object) {
|
||||
super.body(object);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() throws IOException {
|
||||
return resultAs(String.class);
|
||||
|
||||
Reference in New Issue
Block a user