title: Hazelcast with global serializer (Kryo) - There is no suitable de-serializer for type
body: <p>I’m using Hazelcast 3.9 to cluster user sessions.</p>
  
  <p>To serialize the session objects, I created a global serializer implemented with Kryo (or more precisely KryoReflectionFactorySupport that allow to serialize objects without default constructor).</p>
  
  <pre><code>public class GlobalKryoSerializer implements StreamSerializer&lt;Object&gt; {
      //use ThreadLocal because Kryo is not thread safe
      private static final InheritableThreadLocal &lt;Kryo&gt; kryoThreadLocal = new InheritableThreadLocal &lt;Kryo&gt;() {
          @Override
          protected Kryo initialValue() {
             Kryo kryo = new KryoReflectionFactorySupport();
             //Kryo uses its own class loader       
             kryo.setClassLoader(java.lang.Thread.currentThread().getContextClassLoader());
             return kryo;
          }
      };
  
      public GlobalKryoSerializer(){    }
  
      public int getTypeId() {
          return 123;
      }
  
      public void destroy() {    }
  
      public void write(ObjectDataOutput objectDataOutput, Object object) throws IOException {
          Output output = new Output((OutputStream) objectDataOutput);
          Kryo kryo = kryoThreadLocal.get();
          kryo.writeClassAndObject(output, object);
          output.flush();
      }
  
      public Object read(ObjectDataInput objectDataInput) throws IOException {
          InputStream in = (InputStream) objectDataInput;
          Input input = new Input(in);
          Kryo kryo = kryoThreadLocal.get();
          Object retVal = kryo.readClassAndObject(input);
          return retVal;
      }
  }
  </code></pre>
  
  <p>Hazelcast.xml is similar to <a href="https://github.com/hazelcast/hazelcast/blob/master/hazelcast/src/main/resources/hazelcast-default.xml" rel="nofollow noreferrer">https://github.com/hazelcast/hazelcast/blob/master/hazelcast/src/main/resources/hazelcast-default.xml</a> with global serializer configuration:</p>
  
  <pre><code>&lt;serialization&gt;
        &lt;portable-version&gt;0&lt;/portable-version&gt;
        &lt;serializers&gt;
             &lt;global-serializer override-java-serialization="true"&gt; GlobalKryoSerializer&lt;/global-serializer&gt;       
        &lt;/serializers&gt;
  &lt;/serialization&gt;
  </code></pre>
  
  <p>When the session is invalidated, Hazelcast fails to de-serialize with the error below (the “type number” varies from time to time):</p>
  
  <pre><code>com.hazelcast.nio.serialization.HazelcastSerializationException: There is no suitable de-serializer for type 16843028. This exception is likely to be caused by differences in the serialization configuration betw
  een members or between clients and members.
          at com.hazelcast.internal.serialization.impl.AbstractSerializationService.newHazelcastSerializationException(AbstractSerializationService.java:236) ~[hazelcast-all-3.9.jar:3.9]
          at com.hazelcast.internal.serialization.impl.AbstractSerializationService.readObject(AbstractSerializationService.java:263) ~[hazelcast-all-3.9.jar:3.9]
          at com.hazelcast.internal.serialization.impl.ByteArrayObjectDataInput.readObject(ByteArrayObjectDataInput.java:570) ~[hazelcast-all-3.9.jar:3.9]
          at com.hazelcast.session.HazelcastSession.deserializeMap(HazelcastSession.java:141) ~[hazelcast-tomcat7-sessionmanager-1.1.2.jar:na]
          at com.hazelcast.session.HazelcastSession.readData(HazelcastSession.java:127) ~[hazelcast-tomcat7-sessionmanager-1.1.2.jar:na]
          at com.hazelcast.internal.serialization.impl.DataSerializableSerializer.readInternal(DataSerializableSerializer.java:158) ~[hazelcast-all-3.9.jar:3.9]
          at com.hazelcast.internal.serialization.impl.DataSerializableSerializer.read(DataSerializableSerializer.java:105) ~[hazelcast-all-3.9.jar:3.9]
          at com.hazelcast.internal.serialization.impl.DataSerializableSerializer.read(DataSerializableSerializer.java:50) ~[hazelcast-all-3.9.jar:3.9]
          at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48) ~[hazelcast-all-3.9.jar:3.9]
          at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:185) ~[hazelcast-all-3.9.jar:3.9]
          at com.hazelcast.map.impl.proxy.MapProxySupport.toObject(MapProxySupport.java:1149) ~[hazelcast-all-3.9.jar:3.9]
          at com.hazelcast.map.impl.proxy.MapProxyImpl.remove(MapProxyImpl.java:212) ~[hazelcast-all-3.9.jar:3.9]
          at com.hazelcast.session.HazelcastSessionManager.remove(HazelcastSessionManager.java:328) ~[hazelcast-tomcat7-sessionmanager-1.1.2.jar:na]
          at com.hazelcast.session.HazelcastSessionManager.remove(HazelcastSessionManager.java:294) ~[hazelcast-tomcat7-sessionmanager-1.1.2.jar:na]
          at org.apache.catalina.session.StandardSession.expire(StandardSession.java:833) ~[catalina.jar:7.0.82]
          at org.apache.catalina.session.StandardSession.expire(StandardSession.java:732) ~[catalina.jar:7.0.82]
          at org.apache.catalina.session.StandardSession.invalidate(StandardSession.java:1264) ~[catalina.jar:7.0.82]
          at org.apache.catalina.session.StandardSessionFacade.invalidate(StandardSessionFacade.java:183) ~[catalina.jar:7.0.82]
          at org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler.logout(SecurityContextLogoutHandler.java:65) ~[spring-security-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
  </code></pre>