Search code examples
hazelcastjava-custom-serialization

How to configure List<?> type in hazelcast-client.xml for custom Byte array serialization


I have created a custom serialization class using ByteArraySerializer as follows.

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() {
}}

Now I need to configure this in hazelcast-client.xml.I have tried to define as follows.

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

Hazelcast unable recognise the class. Caused by: com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: java.util.List

Is there any way to define type-class in hazelcast-client.xml for collections(List,Set) with generics?


Solution

  • Sorry, the escape characters are rendering correctly, it should be

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