com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer Java Examples

The following examples show how to use com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DbStoragePlainFile.java    From Iron with Apache License 2.0 6 votes vote down vote up
private Kryo createKryoInstance() {
    Kryo kryo = new Kryo();

    kryo.register(IronTable.class);
    kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
    kryo.setReferences(false);

    // Serialize Arrays$ArrayList
    //noinspection ArraysAsListWithZeroOrOneArgument
    kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
    UnmodifiableCollectionsSerializer.registerSerializers(kryo);
    SynchronizedCollectionsSerializer.registerSerializers(kryo);
    // Serialize inner AbstractList$SubAbstractListRandomAccess
    kryo.addDefaultSerializer(new ArrayList<>().subList(0, 0).getClass(),
            new NoArgCollectionSerializer());
    // Serialize AbstractList$SubAbstractList
    kryo.addDefaultSerializer(new LinkedList<>().subList(0, 0).getClass(),
            new NoArgCollectionSerializer());
    // To keep backward compatibility don't change the order of serializers above

    kryo.setInstantiatorStrategy(
            new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
    return kryo;
}
 
Example #2
Source File: DbStoragePlainFile.java    From Paper with Apache License 2.0 5 votes vote down vote up
private Kryo createKryoInstance(boolean compatibilityMode) {
    Kryo kryo = new Kryo();

    if (compatibilityMode) {
        kryo.getFieldSerializerConfig().setOptimizedGenerics(true);
    }

    kryo.register(PaperTable.class);
    kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
    kryo.setReferences(false);

    // Serialize Arrays$ArrayList
    //noinspection ArraysAsListWithZeroOrOneArgument
    kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
    UnmodifiableCollectionsSerializer.registerSerializers(kryo);
    SynchronizedCollectionsSerializer.registerSerializers(kryo);
    // Serialize inner AbstractList$SubAbstractListRandomAccess
    kryo.addDefaultSerializer(new ArrayList<>().subList(0, 0).getClass(),
            new NoArgCollectionSerializer());
    // Serialize AbstractList$SubAbstractList
    kryo.addDefaultSerializer(new LinkedList<>().subList(0, 0).getClass(),
            new NoArgCollectionSerializer());
    // To keep backward compatibility don't change the order of serializers above

    // UUID support
    kryo.register(UUID.class, new UUIDSerializer());

    for (Class<?> clazz : mCustomSerializers.keySet())
        kryo.register(clazz, mCustomSerializers.get(clazz));

    kryo.setInstantiatorStrategy(
            new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));

    return kryo;
}
 
Example #3
Source File: Namespace.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a Kryo instance.
 *
 * @return Kryo instance
 */
@Override
public Kryo create() {
  LOGGER.trace("Creating Kryo instance for {}", this);
  Kryo kryo = new Kryo();
  kryo.setClassLoader(classLoader);
  kryo.setRegistrationRequired(registrationRequired);

  // If compatible serialization is enabled, override the default serializer.
  if (compatible) {
    kryo.setDefaultSerializer(CompatibleFieldSerializer::new);
  }

  // TODO rethink whether we want to use StdInstantiatorStrategy
  kryo.setInstantiatorStrategy(
      new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));

  for (RegistrationBlock block : registeredBlocks) {
    int id = block.begin();
    if (id == FLOATING_ID) {
      id = kryo.getNextRegistrationId();
    }
    for (Pair<Class<?>[], Serializer<?>> entry : block.types()) {
      register(kryo, entry.getLeft(), entry.getRight(), id++);
    }
  }
  return kryo;
}
 
Example #4
Source File: KryoNamespace.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a Kryo instance.
 *
 * @return Kryo instance
 */
@Override
public Kryo create() {
    log.trace("Creating Kryo instance for {}", this);
    Kryo kryo = new Kryo();
    kryo.setRegistrationRequired(registrationRequired);

    // If compatible serialization is enabled, override the default serializer.
    if (compatible) {
        kryo.setDefaultSerializer(CompatibleFieldSerializer::new);
    }

    // TODO rethink whether we want to use StdInstantiatorStrategy
    kryo.setInstantiatorStrategy(
            new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));

    for (RegistrationBlock block : registeredBlocks) {
        int id = block.begin();
        if (id == FLOATING_ID) {
            id = kryo.getNextRegistrationId();
        }
        for (Pair<Class<?>[], Serializer<?>> entry : block.types()) {
            register(kryo, entry.getLeft(), entry.getRight(), id++);
        }
    }
    return kryo;
}
 
Example #5
Source File: KryoSerialization.java    From craft-atom with MIT License 5 votes vote down vote up
private static Kryo newKryo() {
	Kryo kryo = new Kryo();
    kryo.register(RpcBody.class);
    kryo.register(RpcMethod.class);
    kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
    return kryo;
}
 
Example #6
Source File: KryoTranscoder.java    From hibernate4-memcached with Apache License 2.0 4 votes vote down vote up
/**
 * Override this method to change serialization rule.
 *
 * @return Kryo serializer instance.
 */
protected Kryo createKryo() {
    Kryo kryo = new KryoReflectionFactorySupport();
    kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
    return kryo;
}