简体   繁体   中英

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?

Without testing if your definition will load correctly, you can fix your definition by properly escaping the "<" and ">" characters:

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

as such:

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM