0

我使用 ByteArraySerializer 创建了一个自定义序列化类,如下所示。

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 中进行配置。我尝试定义如下。

<serialization>
<serializers>
  <serializer class-name="com.XXX.serializer.ProgramListSerailizer" type-class="java.util.List&lt;com.xxx.Program&gt;"/>
</serializers>

Hazelcast 无法识别类。引起:com.hazelcast.nio.serialization.HazelcastSerializationException:java.lang.ClassNotFoundException:java.util.List

有没有办法在 hazelcast-client.xml 中为具有泛型的集合(List,Set)定义类型类?

4

2 回答 2

0

抱歉,转义字符渲染正确,应该是

"&lt;" = "<"
"&gt;" = ">"
于 2018-07-30T16:48:21.153 回答
0

在不测试您的定义是否会正确加载的情况下,您可以通过正确转义“<”和“>”字符来修复您的定义:

"<" = "<" ">" = ">"

像这样:

type-class="java.util.List<com.xxx.Program>"

于 2018-07-30T16:36:41.943 回答