Package com.imyeyu.network
Class JacksonRequest
java.lang.Object
com.imyeyu.network.CommonRequest
com.imyeyu.network.JacksonRequest
- Direct Known Subclasses:
FileRequest,TimiRequest
基于 Jackson 的请求封装。
- Since:
- 2025-07-15 14:27
- Author:
- 夜雨
-
Field Summary
Fields inherited from class com.imyeyu.network.CommonRequest
request -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedJacksonRequest(org.apache.hc.client5.http.fluent.Request request) -
Method Summary
Modifier and TypeMethodDescriptioncom.fasterxml.jackson.databind.node.ArrayNode将响应体解析为 JSON 数组。com.fasterxml.jackson.databind.JsonNode将响应体解析为 JSON 节点。com.fasterxml.jackson.databind.node.ObjectNode将响应体解析为 JSON 对象。设置 JSON 请求体。bodyEntity(org.apache.hc.core5.http.HttpEntity entity) static JacksonRequest创建 GET 请求。protected com.fasterxml.jackson.databind.ObjectMapper获取当前请求使用的对象映射器。objectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) 指定对象映射器。static JacksonRequest创建 POST 请求。<T> TresultAs(com.fasterxml.jackson.core.type.TypeReference<T> typeReference) 将响应体解析为指定泛型类型。<T> T将响应体解析为指定类型。<T> T将响应体解析为指定反射类型。timeout(long ms) static JacksonRequestwrap(org.apache.hc.client5.http.fluent.Request request) 包装现有请求对象。
-
Constructor Details
-
JacksonRequest
protected JacksonRequest(org.apache.hc.client5.http.fluent.Request request)
-
-
Method Details
-
getObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()获取当前请求使用的对象映射器。- Returns:
- 对象映射器
-
wrap
包装现有请求对象。- Parameters:
request- 请求对象- Returns:
- Jackson 请求
-
get
创建 GET 请求。- Parameters:
url- 请求地址- Returns:
- Jackson 请求
-
post
创建 POST 请求。- Parameters:
url- 请求地址- Returns:
- Jackson 请求
-
objectMapper
指定对象映射器。- Parameters:
objectMapper- 对象映射器- Returns:
- 当前请求
-
timeout
- Overrides:
timeoutin classCommonRequest
-
header
- Overrides:
headerin classCommonRequest
-
token
- Overrides:
tokenin classCommonRequest
-
language
- Overrides:
languagein classCommonRequest
-
body
设置 JSON 请求体。- Parameters:
object- 要序列化的对象- Returns:
- 当前请求
- Throws:
IllegalArgumentException- JSON 序列化失败时抛出
-
bodyEntity
- Overrides:
bodyEntityin classCommonRequest
-
resultAs
将响应体解析为指定类型。- Type Parameters:
T- 结果类型- Parameters:
clazz- 目标类型- Returns:
- 解析结果
- Throws:
IOException- 读取或解析失败
-
resultAs
public <T> T resultAs(com.fasterxml.jackson.core.type.TypeReference<T> typeReference) throws IOException 将响应体解析为指定泛型类型。- Type Parameters:
T- 结果类型- Parameters:
typeReference- 目标类型引用- Returns:
- 解析结果
- Throws:
IOException- 读取或解析失败
-
resultAs
将响应体解析为指定反射类型。- Type Parameters:
T- 结果类型- Parameters:
type- 目标类型- Returns:
- 解析结果
- Throws:
IOException- 读取或解析失败
-
asJsonNode
将响应体解析为 JSON 节点。- Returns:
- JSON 节点
- Throws:
IOException- 读取或解析失败
-
asJsonObject
将响应体解析为 JSON 对象。- Returns:
- JSON 对象节点
- Throws:
IOException- 读取或解析失败
-
asJsonArray
将响应体解析为 JSON 数组。- Returns:
- JSON 数组节点
- Throws:
IOException- 读取或解析失败
-