简体   繁体   English

如何配置列表 <?> 输入hazelcast-client.xml以进行自定义字节数组序列化

[英]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. 我使用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() {
}}

Now I need to configure this in hazelcast-client.xml.I have tried to define as follows. 现在我需要在hazelcast-client.xml中配置它,我尝试定义如下。

<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. Hazelcast无法识别该班级。 Caused by: com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: java.util.List 引起原因: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? 有什么办法可以在hazelcast-client.xml中为具有泛型的collection(List,Set)定义类型类?

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>" 型级= “java.util.List的<com.xxx.Program>”

Sorry, the escape characters are rendering correctly, it should be 抱歉,转义字符正确呈现,应该是

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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