如何在 hazelcast-client.xml 中配置 List<?> 类型以进行自定义字节数组序列化
How to configure List<?> type in hazelcast-client.xml for custom Byte array serialization
我使用 ByteArraySerializer 创建了一个自定义序列化 class,如下所示。
public class ProgramListSerializer implements ByteArraySerializer<List<Program>> {
public static final TypeReference<List<Program>> LIST_PROGRAM_TYPE = new TypeReference<List<Program>>() {};
private ObjectMapper mapper = new ObjectMapper(new SmileFactory());
public ProgramListSerializer() {
}
public int getTypeId() {
return 1001;
}
public byte[] write(List<Program> object) throws IOException {
return this.mapper.writeValueAsBytes(object);
}
public List<Program> read(byte[] buffer) throws IOException {
return this.mapper.readValue(buffer, LIST_PROGRAM_TYPE);
}
public void destroy() {
}}
现在我需要在hazelcast中配置这个-client.xml.I已经尝试定义如下。
<serialization>
<serializers>
<serializer class-name="com.XXX.serializer.ProgramListSerailizer" type-class="java.util.List<com.xxx.Program>"/>
</serializers>
Hazelcast 无法识别 class。原因:com.hazelcast.nio.serialization.HazelcastSerializationException:java.lang.ClassNotFoundException:java.util.List
有什么方法可以在 hazelcast-client.xml 中为带有泛型的集合(List、Set)定义类型-class?
无需测试您的定义是否会正确加载,您可以通过正确转义“<”和“>”字符来修复您的定义:
“<”=“<”
">" = ">"
这样:
类型-class="java.util.List<com.xxx.Program>"
抱歉,转义字符渲染正确,应该是
"<" = "<"
">" = ">"
我使用 ByteArraySerializer 创建了一个自定义序列化 class,如下所示。
public class ProgramListSerializer implements ByteArraySerializer<List<Program>> {
public static final TypeReference<List<Program>> LIST_PROGRAM_TYPE = new TypeReference<List<Program>>() {};
private ObjectMapper mapper = new ObjectMapper(new SmileFactory());
public ProgramListSerializer() {
}
public int getTypeId() {
return 1001;
}
public byte[] write(List<Program> object) throws IOException {
return this.mapper.writeValueAsBytes(object);
}
public List<Program> read(byte[] buffer) throws IOException {
return this.mapper.readValue(buffer, LIST_PROGRAM_TYPE);
}
public void destroy() {
}}
现在我需要在hazelcast中配置这个-client.xml.I已经尝试定义如下。
<serialization>
<serializers>
<serializer class-name="com.XXX.serializer.ProgramListSerailizer" type-class="java.util.List<com.xxx.Program>"/>
</serializers>
Hazelcast 无法识别 class。原因:com.hazelcast.nio.serialization.HazelcastSerializationException:java.lang.ClassNotFoundException:java.util.List
有什么方法可以在 hazelcast-client.xml 中为带有泛型的集合(List、Set)定义类型-class?
无需测试您的定义是否会正确加载,您可以通过正确转义“<”和“>”字符来修复您的定义:
“<”=“<” ">" = ">"
这样:
类型-class="java.util.List<com.xxx.Program>"
抱歉,转义字符渲染正确,应该是
"<" = "<"
">" = ">"