1.4. Marshalled Java 对象
Data Grid 将 marshalled Java 对象存储在缓存中作为字节数组。例如,以下是作为内存中值存储的 Person 对象的简单表示:
value=[61 6c 61 6e 0a 70 61 72 74 72 69 64 67 65]
要将 marshalled 对象存储到缓存中,您应该使用 ProtoStream marshaller,除非存在严格的要求。例如,当从旧版本的 Data Grid 迁移客户端应用程序时,您可能需要临时将 JBoss marshalling 与 Hot Rod Java 客户端一起使用。
Data Grid 将 marshalled Java 对象存储为带有以下介质类型的字节阵列:
-
application/x-protostream -
application/x-jboss-marshalling -
application/x-java-serialized-object
在存储未归档的 Java 对象时,Data Grid 使用 equals () 和 hashCode () 的对象实现。在存储 marshalled 对象时,比较 marshalled 字节以相等和散列。
1.4.1. 客户端和 marshalled 对象 复制链接链接已复制到粘贴板!
当您将 Hot Rod Java 客户端配置为使用 marshaller 时,您必须使用该 marshaller 的编码来配置您的缓存。
每个 marshaller 使用不同的介质类型来生成 byte[] 内容,客户端可以传送到 Data Grid Server。从服务器读取时,客户端 marshaller 会执行相反的操作,使用介质类型从 byte[] 内容生成数据。
您的缓存编码必须与 Hot Rod 客户端 marshaller 兼容。例如,如果您将缓存编码配置为 application/x-protostream,您可以将 ProtoStream marshaller 与客户端一同操作。但是,如果客户端 marshaller 使用 Data Grid 无法转换为或从 application/x-protostream 转换的编码,Data Grid 会抛出错误消息。
如果您使用 JavaSerializationMarshaller 或 GenericJBossMarshaller,您应该分别使用 application/x-java-serialized-object 或 application/x-jboss-marshalling 介质类型对缓存进行编码。
ProtoStream 转换为 JSON 转换
Data Grid 将使用 application/x-protostream 介质类型编码的键和值转换为 application/json。
这允许 REST 客户端在请求标头中包含 JSON 介质类型,并对使用 ProtoStream 编码的缓存执行操作:
-
接受:用于读取操作的应用程序/json。 -
content-Type:用于写入操作的 application/json。