Reputation: 77
I am running an embedded hazelcast deployment and storing a ConcurrentMap<String, MyType>
, where the type of value in the map is my custom class.
public class MyType implements Serializable {
private MyTag tag;
...
}
One of its fields is an interface MyTag
.
public interface MyTag<T> {
}
And I have a class containing several enum implementations of MyTag
interface:
public class MyTags {
public static enum Integers implements MyTag<Integer> {
INT_TAG1,
INT_TAG2,
...
}
public static enum Strings implements MyTag<String> {
STRING_TAG1,
...
}
...
}
After moving MyTags
class to a different package and redeploying one of my services (with MyType
in the new package) upon attempting a get on the map, an exception is thrown:
com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: old.package.MyTags$Strings
How could I protect myself from this situation when deploying on a production environment?
Upvotes: 0
Views: 386
Reputation: 26858
Java's Serializable
depends on the class remaining the exact same. A moved class is no longer the same class. Select one of the other options that Hazelcast has for serialization of objects. See Comparing Serialization Options for some more guidance on the different options.
Upvotes: 1