Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9807de4c4 | ||
|
|
113cdeb0d9 |
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.imyeyu.network</groupId>
|
<groupId>com.imyeyu.network</groupId>
|
||||||
<artifactId>timi-network</artifactId>
|
<artifactId>timi-network</artifactId>
|
||||||
<version>0.0.14</version>
|
<version>0.1.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@@ -106,7 +106,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.io</groupId>
|
<groupId>com.imyeyu.io</groupId>
|
||||||
<artifactId>timi-io</artifactId>
|
<artifactId>timi-io</artifactId>
|
||||||
<version>0.0.5</version>
|
<version>0.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents.client5</groupId>
|
<groupId>org.apache.httpcomponents.client5</groupId>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.imyeyu.network;
|
|||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.JavaType;
|
import com.fasterxml.jackson.databind.JavaType;
|
||||||
import com.imyeyu.java.bean.CallbackArg;
|
import com.imyeyu.java.bean.CallbackArg;
|
||||||
import com.imyeyu.java.bean.timi.TimiResponse;
|
import com.imyeyu.java.bean.Response;
|
||||||
import org.apache.hc.client5.http.fluent.Request;
|
import org.apache.hc.client5.http.fluent.Request;
|
||||||
import org.apache.hc.core5.http.HttpEntity;
|
import org.apache.hc.core5.http.HttpEntity;
|
||||||
import org.apache.hc.core5.http.HttpResponse;
|
import org.apache.hc.core5.http.HttpResponse;
|
||||||
@@ -94,7 +94,7 @@ public class TimiRequest extends JacksonRequest {
|
|||||||
* @throws IOException 读取或解析失败
|
* @throws IOException 读取或解析失败
|
||||||
*/
|
*/
|
||||||
public <T> T resultAs(Class<T> clazz) throws IOException {
|
public <T> T resultAs(Class<T> clazz) throws IOException {
|
||||||
TimiResponse<T> resp = getObjectMapper().treeToValue(asJsonObject(), timiResponseType(clazz));
|
Response<T> resp = getObjectMapper().treeToValue(asJsonObject(), timiResponseType(clazz));
|
||||||
if (resp.isFail()) {
|
if (resp.isFail()) {
|
||||||
throw resp.toException();
|
throw resp.toException();
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,7 @@ public class TimiRequest extends JacksonRequest {
|
|||||||
* @throws IOException 读取或解析失败
|
* @throws IOException 读取或解析失败
|
||||||
*/
|
*/
|
||||||
public <T> T resultAs(TypeReference<T> typeReference) throws IOException {
|
public <T> T resultAs(TypeReference<T> typeReference) throws IOException {
|
||||||
TimiResponse<T> resp = getObjectMapper().treeToValue(asJsonObject(), timiResponseType(typeReference));
|
Response<T> resp = getObjectMapper().treeToValue(asJsonObject(), timiResponseType(typeReference));
|
||||||
if (resp.isFail()) {
|
if (resp.isFail()) {
|
||||||
throw resp.toException();
|
throw resp.toException();
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ public class TimiRequest extends JacksonRequest {
|
|||||||
* @throws IOException 读取或解析失败
|
* @throws IOException 读取或解析失败
|
||||||
*/
|
*/
|
||||||
public <T> T resultAs(Type type) throws IOException {
|
public <T> T resultAs(Type type) throws IOException {
|
||||||
TimiResponse<T> resp = getObjectMapper().treeToValue(asJsonObject(), timiResponseType(type));
|
Response<T> resp = getObjectMapper().treeToValue(asJsonObject(), timiResponseType(type));
|
||||||
if (resp.isFail()) {
|
if (resp.isFail()) {
|
||||||
throw resp.toException();
|
throw resp.toException();
|
||||||
}
|
}
|
||||||
@@ -135,7 +135,7 @@ public class TimiRequest extends JacksonRequest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws IOException {
|
public void execute() throws IOException {
|
||||||
TimiResponse<?> resp = getObjectMapper().treeToValue(asJsonObject(), timiResponseType(Object.class));
|
Response<?> resp = getObjectMapper().treeToValue(asJsonObject(), timiResponseType(Object.class));
|
||||||
if (resp.isFail()) {
|
if (resp.isFail()) {
|
||||||
throw resp.toException();
|
throw resp.toException();
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,7 @@ public class TimiRequest extends JacksonRequest {
|
|||||||
* @return Jackson 类型
|
* @return Jackson 类型
|
||||||
*/
|
*/
|
||||||
protected JavaType timiResponseType(Class<?> clazz) {
|
protected JavaType timiResponseType(Class<?> clazz) {
|
||||||
return getObjectMapper().getTypeFactory().constructParametricType(TimiResponse.class, clazz);
|
return getObjectMapper().getTypeFactory().constructParametricType(Response.class, clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -158,7 +158,7 @@ public class TimiRequest extends JacksonRequest {
|
|||||||
* @return Jackson 类型
|
* @return Jackson 类型
|
||||||
*/
|
*/
|
||||||
protected JavaType timiResponseType(TypeReference<?> typeReference) {
|
protected JavaType timiResponseType(TypeReference<?> typeReference) {
|
||||||
return getObjectMapper().getTypeFactory().constructParametricType(TimiResponse.class, getObjectMapper().constructType(typeReference));
|
return getObjectMapper().getTypeFactory().constructParametricType(Response.class, getObjectMapper().constructType(typeReference));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -168,6 +168,6 @@ public class TimiRequest extends JacksonRequest {
|
|||||||
* @return Jackson 类型
|
* @return Jackson 类型
|
||||||
*/
|
*/
|
||||||
protected JavaType timiResponseType(Type type) {
|
protected JavaType timiResponseType(Type type) {
|
||||||
return getObjectMapper().getTypeFactory().constructParametricType(TimiResponse.class, getObjectMapper().constructType(type));
|
return getObjectMapper().getTypeFactory().constructParametricType(Response.class, getObjectMapper().constructType(type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user