如何在hazelcast-client.xml中配置List <!-?->类型以自定义字节数组序列化

时间:2018-07-30 15:28:44

标签: hazelcast java-custom-serialization

我使用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中为具有泛型的collection(List,Set)定义类型类?

2 个答案:

答案 0 :(得分:0)

如果不测试定义是否可以正确加载,则可以通过正确转义“ <”和“>”字符来修正定义:

“ <” =“ <” “>” =“>”

例如:

type-class =“ java.util.List

答案 1 :(得分:0)

抱歉,转义字符正确呈现,应该是

"&lt;" = "<"
"&gt;" = ">"