[英]How to configure custom serializer for all custom types in Hazelcast
Would it be correct to set custom serializer for Object.class
:为
Object.class
设置自定义序列化器是否正确:
new Config().getSerializationConfig().addSerializerConfig(
new SerializerConfig()
.setImplementation(new MySerializer())
.setTypeClass(Object.class)
);
or should I use some wrapper class when puting or geting some value to/from Hazelcast:或者我应该在向/从 Hazelcast 放置或获取一些值时使用一些包装类:
new Config().getSerializationConfig().addSerializerConfig(
new SerializerConfig()
.setImplementation(new MySerializer())
.setTypeClass(MyWrapper.class)
);
hazelcast.getMap("some map").put("my key", new MyWrapper(anyCustomValue));
Every java class extends Object.
每个java类都扩展了Object。
Storing object type can be a solution to store multiple class types.存储对象类型可以是存储多个类类型的解决方案。 But,
但,
If you need to store different class types in your hazelcast map
, I can suggest you to use a wrapper object to cover them and cover that object serialization requirement in your single serialization class.如果您需要在您的
hazelcast map
存储不同的类类型,我可以建议您使用包装器对象来覆盖它们并在您的单个序列化类中覆盖该对象序列化要求。 Obviously, this way gives you more control of your objects to manage like get and set.显然,这种方式可以让您更好地控制要管理的对象,例如 get 和 set。 Otherwise, you may need a couple of implementation to cover types of an object to cast which one is.
否则,您可能需要几个实现来覆盖要强制转换的对象类型。 And managing this situation can be painful in the future instead of using a single wrapper object.
管理这种情况在未来可能会很痛苦,而不是使用单个包装器对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.