Class JsonBody
java.lang.Object
cloud.opencode.base.web.body.JsonBody
- All Implemented Interfaces:
RequestBody
JSON Body - JSON Request Body
JSON 请求体 - JSON 请求体
Features | 主要功能:
- JSON string request body - JSON 字符串请求体
- Map to JSON conversion - Map 到 JSON 转换
- Pluggable serializer support - 可插拔序列化器支持
- Automatic UTF-8 encoding - 自动 UTF-8 编码
Usage Examples | 使用示例:
// From JSON string
JsonBody body = JsonBody.of("{\"name\":\"John\"}");
// From Map
JsonBody body = JsonBody.of(Map.of("name", "John", "age", 30));
// From object with custom serializer
JsonBody.setSerializer(obj -> mySerializer.toJson(obj));
JsonBody body = JsonBody.of(myObject);
Security | 安全性:
- Thread-safe: Yes (immutable after construction) - 线程安全: 是(构建后不可变)
- Null-safe: No (json content must not be null) - 空值安全: 否(JSON 内容不能为 null)
- Since:
- JDK 25, opencode-base-web V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface RequestBody
RequestBody.SimpleBody -
Method Summary
-
Method Details
-
of
-
of
-
of
-
of
-
setSerializer
-
getSerializer
-
getContentType
- Specified by:
getContentTypein interfaceRequestBody
-
getBodyPublisher
- Specified by:
getBodyPublisherin interfaceRequestBody
-
getContentLength
public long getContentLength()- Specified by:
getContentLengthin interfaceRequestBody
-
getJson
-
toString
-