public void writeObject(final ObjectDataOutput out, final Object obj) {
   final boolean isNull = obj == null;
   try {
     out.writeBoolean(isNull);
     if (isNull) {
       return;
     }
     final SerializerAdapter serializer = serializerFor(obj.getClass());
     if (serializer == null) {
       if (active) {
         throw new HazelcastSerializationException(
             "There is no suitable serializer for " + obj.getClass());
       }
       throw new HazelcastInstanceNotActiveException();
     }
     out.writeInt(serializer.getTypeId());
     if (obj instanceof Portable) {
       final Portable portable = (Portable) obj;
       ClassDefinition classDefinition =
           serializationContext.lookupOrRegisterClassDefinition(portable);
       classDefinition.writeData(out);
     }
     serializer.write(out, obj);
   } catch (Throwable e) {
     handleException(e);
   }
 }
 private void safeRegister(final Class type, final SerializerAdapter serializer) {
   if (constantTypesMap.containsKey(type)) {
     throw new IllegalArgumentException("[" + type + "] serializer cannot be overridden!");
   }
   SerializerAdapter current = typeMap.putIfAbsent(type, serializer);
   if (current != null && current.getImpl().getClass() != serializer.getImpl().getClass()) {
     throw new IllegalStateException(
         "Serializer[" + current.getImpl() + "] has been already registered for type: " + type);
   }
   current = idMap.putIfAbsent(serializer.getTypeId(), serializer);
   if (current != null && current.getImpl().getClass() != serializer.getImpl().getClass()) {
     throw new IllegalStateException(
         "Serializer ["
             + current.getImpl()
             + "] has been already registered for type-id: "
             + serializer.getTypeId());
   }
 }
 @SuppressWarnings("unchecked")
 public Data toData(Object obj, PartitioningStrategy strategy) {
   if (obj == null) {
     return null;
   }
   if (obj instanceof Data) {
     return (Data) obj;
   }
   try {
     final SerializerAdapter serializer = serializerFor(obj.getClass());
     if (serializer == null) {
       if (active) {
         throw new HazelcastSerializationException(
             "There is no suitable serializer for " + obj.getClass());
       }
       throw new HazelcastInstanceNotActiveException();
     }
     final byte[] bytes = serializer.write(obj);
     final Data data = new Data(serializer.getTypeId(), bytes);
     if (obj instanceof Portable) {
       final Portable portable = (Portable) obj;
       data.classDefinition =
           serializationContext.lookup(portable.getFactoryId(), portable.getClassId());
     }
     if (strategy == null) {
       strategy = globalPartitioningStrategy;
     }
     if (strategy != null) {
       Object pk = strategy.getPartitionKey(obj);
       if (pk != null && pk != obj) {
         final Data partitionKey = toData(pk, EMPTY_PARTITIONING_STRATEGY);
         data.partitionHash = (partitionKey == null) ? -1 : partitionKey.getPartitionHash();
       }
     }
     return data;
   } catch (Throwable e) {
     handleException(e);
   }
   return null;
 }
 private void registerConstant(Class type, SerializerAdapter serializer) {
   constantTypesMap.put(type, serializer);
   constantTypeIds[indexForDefaultType(serializer.getTypeId())] = serializer;
 }