4.4. 以基于文本的格式存储数据
配置 Data Grid 以基于文本的格式存储数据,如 text/ plain、application/json 或 application/xml。
流程
- 将基于文本的存储格式指定为键和值的 MediaType。
(可选)指定字符集,如
UTF-8。以下示例将 Data Grid 配置为存储带有
text/plain 的条目;charset=UTF-8格式:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 配置您的客户端。
热 Rod 客户端可以使用 org.infinispan.commons.marshall.StringMarshaller 处理纯文本、JSON、XML 或任何其他基于文本的格式。
您还可以将基于文本的格式与 ProtoStream marshaller 搭配使用。ProtoStream 可以原生处理 String 和 byte[] 类型,而无需创建 Serialization 上下文并注册 Protobuf 模式(.proto 文件)。
REST 客户端必须使用请求发送正确的标头:
-
accept: text/plain; charset=UTF-8用于读取操作。 -
Content-Type: text/plain; charset=UTF-8用于写入操作。