Search in sources :

Example 11 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class PortableSerializer method createNewPortableInstance.

private Portable createNewPortableInstance(int factoryId, int classId) {
    final PortableFactory portableFactory = factories.get(factoryId);
    if (portableFactory == null) {
        throw new HazelcastSerializationException("Could not find PortableFactory for factory-id: " + factoryId);
    }
    final Portable portable = portableFactory.create(classId);
    if (portable == null) {
        throw new HazelcastSerializationException("Could not create Portable for class-id: " + classId);
    }
    return portable;
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) PortableFactory(com.hazelcast.nio.serialization.PortableFactory)

Example 12 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class SerializationServiceV1 method registerClassDefinition.

protected void registerClassDefinition(ClassDefinition cd, Map<Integer, ClassDefinition> classDefMap, boolean checkClassDefErrors) {
    final Set<String> fieldNames = cd.getFieldNames();
    for (String fieldName : fieldNames) {
        FieldDefinition fd = cd.getField(fieldName);
        if (fd.getType() == FieldType.PORTABLE || fd.getType() == FieldType.PORTABLE_ARRAY) {
            int classId = fd.getClassId();
            ClassDefinition nestedCd = classDefMap.get(classId);
            if (nestedCd != null) {
                registerClassDefinition(nestedCd, classDefMap, checkClassDefErrors);
                portableContext.registerClassDefinition(nestedCd);
            } else if (checkClassDefErrors) {
                throw new HazelcastSerializationException("Could not find registered ClassDefinition for class-id: " + classId);
            }
        }
    }
    portableContext.registerClassDefinition(cd);
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition)

Example 13 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class AbstractSerializationService method serializerFor.

protected final SerializerAdapter serializerFor(Object object) {
    //1-NULL serializer
    if (object == null) {
        return nullSerializerAdapter;
    }
    Class type = object.getClass();
    //2-Default serializers, Dataserializable, Portable, primitives, arrays, String and some helper Java types(BigInteger etc)
    SerializerAdapter serializer = lookupDefaultSerializer(type);
    //3-Custom registered types by user
    if (serializer == null) {
        serializer = lookupCustomSerializer(type);
    }
    //4-JDK serialization ( Serializable and Externalizable )
    if (serializer == null && !overrideJavaSerialization) {
        serializer = lookupJavaSerializer(type);
    }
    //5-Global serializer if registered by user
    if (serializer == null) {
        serializer = lookupGlobalSerializer(type);
    }
    if (serializer == null) {
        if (active) {
            throw new HazelcastSerializationException("There is no suitable serializer for " + type);
        }
        throw new HazelcastInstanceNotActiveException();
    }
    return serializer;
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) SerializationUtil.createSerializerAdapter(com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)

Example 14 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class ByteArraySerializerAdapter method read.

@Override
public Object read(ObjectDataInput in, Class aClass) throws IOException {
    byte[] bytes = in.readByteArray();
    if (bytes == null) {
        return null;
    }
    if (!(serializer instanceof TypedByteArrayDeserializer)) {
        throw new HazelcastSerializationException(serializer + " is not implementing the " + TypedByteArrayDeserializer.class + " interface. Please implement this interface to deserialize for class " + aClass);
    }
    TypedByteArrayDeserializer deserializer = (TypedByteArrayDeserializer) serializer;
    return deserializer.read(bytes, aClass);
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) TypedByteArrayDeserializer(com.hazelcast.nio.serialization.TypedByteArrayDeserializer)

Example 15 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class ClassDefinitionWriter method writePortable.

@Override
public void writePortable(String fieldName, Portable portable) throws IOException {
    if (portable == null) {
        throw new HazelcastSerializationException("Cannot write null portable without explicitly " + "registering class definition!");
    }
    int version = SerializationUtil.getPortableVersion(portable, context.getVersion());
    ClassDefinition nestedClassDef = createNestedClassDef(portable, new ClassDefinitionBuilder(portable.getFactoryId(), portable.getClassId(), version));
    builder.addPortableField(fieldName, nestedClassDef);
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder)

Aggregations

HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)17 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)5 IOException (java.io.IOException)3 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)2 BufferObjectDataInput (com.hazelcast.nio.BufferObjectDataInput)2 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)2 DataSerializableFactory (com.hazelcast.nio.serialization.DataSerializableFactory)2 FieldDefinition (com.hazelcast.nio.serialization.FieldDefinition)2 Portable (com.hazelcast.nio.serialization.Portable)2 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)2 Serializer (com.hazelcast.nio.serialization.Serializer)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)1 SerializerConfig (com.hazelcast.config.SerializerConfig)1 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)1 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 InputOutputFactory (com.hazelcast.internal.serialization.InputOutputFactory)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 SerializationUtil.isNullData (com.hazelcast.internal.serialization.impl.SerializationUtil.isNullData)1