Search in sources :

Example 1 with VersionedPortable

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

the class SampleMetadataResolver method resolve.

@Nullable
@SuppressWarnings("checkstyle:returncount")
static Metadata resolve(InternalSerializationService ss, Object target, boolean key) {
    try {
        if (target instanceof Data) {
            Data data = (Data) target;
            if (data.isPortable()) {
                ClassDefinition classDefinition = ss.getPortableContext().lookupClassDefinition(data);
                return resolvePortable(classDefinition, key);
            } else if (data.isCompact()) {
                return resolveCompact(ss.extractSchemaFromData(data), key);
            } else if (data.isJson()) {
                return null;
            } else {
                return resolveJava(ss.toObject(data).getClass(), key);
            }
        } else if (target instanceof VersionedPortable) {
            VersionedPortable portable = (VersionedPortable) target;
            ClassDefinition classDefinition = ss.getPortableContext().lookupClassDefinition(portable.getFactoryId(), portable.getClassId(), portable.getClassVersion());
            return resolvePortable(classDefinition, key);
        } else if (target instanceof Portable) {
            Portable portable = (Portable) target;
            ClassDefinition classDefinition = ss.getPortableContext().lookupClassDefinition(portable.getFactoryId(), portable.getClassId(), 0);
            return resolvePortable(classDefinition, key);
        } else if (target instanceof PortableGenericRecord) {
            return resolvePortable(((PortableGenericRecord) target).getClassDefinition(), key);
        } else if (target instanceof CompactGenericRecord) {
            return resolveCompact(((CompactGenericRecord) target).getSchema(), key);
        } else if (ss.isCompactSerializable(target)) {
            Schema schema = ss.extractSchemaFromObject(target);
            return resolveCompact(schema, key);
        } else if (target instanceof HazelcastJsonValue) {
            return null;
        } else {
            return resolveJava(target.getClass(), key);
        }
    } catch (Exception e) {
        return null;
    }
}
Also used : VersionedPortable(com.hazelcast.nio.serialization.VersionedPortable) Portable(com.hazelcast.nio.serialization.Portable) PortableGenericRecord(com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord) Schema(com.hazelcast.internal.serialization.impl.compact.Schema) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) CompactGenericRecord(com.hazelcast.internal.serialization.impl.compact.CompactGenericRecord) Data(com.hazelcast.internal.serialization.Data) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) VersionedPortable(com.hazelcast.nio.serialization.VersionedPortable) Nullable(javax.annotation.Nullable)

Example 2 with VersionedPortable

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

the class SerializationUtil method getPortableVersion.

public static int getPortableVersion(Portable portable, int defaultVersion) {
    int version = defaultVersion;
    if (portable instanceof VersionedPortable) {
        VersionedPortable versionedPortable = (VersionedPortable) portable;
        version = versionedPortable.getClassVersion();
        if (version < 0) {
            throw new IllegalArgumentException("Version cannot be negative!");
        }
    }
    return version;
}
Also used : VersionedPortable(com.hazelcast.nio.serialization.VersionedPortable)

Aggregations

VersionedPortable (com.hazelcast.nio.serialization.VersionedPortable)2 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)1 Data (com.hazelcast.internal.serialization.Data)1 CompactGenericRecord (com.hazelcast.internal.serialization.impl.compact.CompactGenericRecord)1 Schema (com.hazelcast.internal.serialization.impl.compact.Schema)1 PortableGenericRecord (com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord)1 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)1 Portable (com.hazelcast.nio.serialization.Portable)1 Nullable (javax.annotation.Nullable)1