我使用 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<com.xxx.Program>"/>
</serializers>
Hazelcast 无法识别类。引起:com.hazelcast.nio.serialization.HazelcastSerializationException:java.lang.ClassNotFoundException:java.util.List
有没有办法在 hazelcast-client.xml 中为具有泛型的集合(List,Set)定义类型类?