Java Code Examples for com.esotericsoftware.kryo.Kryo#addDefaultSerializer()

The following examples show how to use com.esotericsoftware.kryo.Kryo#addDefaultSerializer() . 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: RelTraitSerializers.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public static void register(final Kryo kryo) {
  final EnumSerializer enumSerializer = new EnumSerializer();
  kryo.addDefaultSerializer(BindableConvention.class, enumSerializer);
  kryo.addDefaultSerializer(EnumerableConvention.class, enumSerializer);
  kryo.addDefaultSerializer(InterpretableConvention.class, enumSerializer);
  kryo.addDefaultSerializer(Convention.Impl.class, ConventionSerializer.class);

  kryo.addDefaultSerializer(RelDistributions.SINGLETON.getClass(), RelDistributionSerializer.class);
  kryo.addDefaultSerializer(DistributionTrait.class, DistributionTraitSerializer.class);
  kryo.addDefaultSerializer(RelCollation.class, RelCollationSerializer.class);

  kryo.addDefaultSerializer(RelTraitSet.class, RelTraitSetSerializer.class);
}
 
Example 3
Source File: ImmutableCollectionSerializers.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public static void register(final Kryo kryo) {
  // register list
  ImmutableListSerializer.register(kryo);
  // register set
  ImmutableSetSerializer.register(kryo);
  // register set
  ImmutableMapSerializer.register(kryo);
  // others
  kryo.addDefaultSerializer(FlatLists.AbstractFlatList.class, FieldSerializer.class);
  kryo.addDefaultSerializer(ImmutableNullableList.class, ImmutableNullableListSerializer.class);
}
 
Example 4
Source File: KryoSerializer.java    From Jupiter with Apache License 2.0 5 votes vote down vote up
@Override
protected Kryo initialValue() throws Exception {
    Kryo kryo = new Kryo();
    for (Class<?> type : useJavaSerializerTypes) {
        kryo.addDefaultSerializer(type, JavaSerializer.class);
    }
    kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
    kryo.setRegistrationRequired(false);
    kryo.setReferences(false);
    return kryo;
}
 
Example 5
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 6
Source File: Kryo5Codec.java    From redisson with Apache License 2.0 5 votes vote down vote up
protected Kryo createKryo(ClassLoader classLoader) {
    Kryo kryo = new Kryo();
    if (classLoader != null) {
        kryo.setClassLoader(classLoader);
    }
    kryo.setRegistrationRequired(false);
    kryo.setReferences(false);
    kryo.addDefaultSerializer(Throwable.class, new JavaSerializer());
    return kryo;
}
 
Example 7
Source File: JavaSerializers.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static void register(final Kryo kryo) {
  kryo.addDefaultSerializer(URI.class, URISerializer.class);
}
 
Example 8
Source File: RelTraitDefSerializers.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static void register(final Kryo kryo) {
  kryo.addDefaultSerializer(RelCollationTraitDef.class, SingletonSerializer.of(Suppliers.ofInstance(RelCollationTraitDef.INSTANCE)));
  kryo.addDefaultSerializer(DistributionTraitDef.class, SingletonSerializer.of(Suppliers.ofInstance(DistributionTraitDef.INSTANCE)));
  kryo.addDefaultSerializer(RelDistributionTraitDef.class, SingletonSerializer.of(Suppliers.ofInstance(RelDistributionTraitDef.INSTANCE)));
  kryo.addDefaultSerializer(ConventionTraitDef.class, SingletonSerializer.of(Suppliers.ofInstance(ConventionTraitDef.INSTANCE)));
}
 
Example 9
Source File: KryoReadingSerializer.java    From kafka-serializer-example with MIT License 4 votes vote down vote up
protected Kryo initialValue() {
    Kryo kryo = new Kryo();
    kryo.addDefaultSerializer(SensorReading.class, new KryoInternalSerializer());
    return kryo;
}
 
Example 10
Source File: KryoSerialization.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected Kryo newKryoInstance() {
    Kryo kryo = new Kryo(new DefaultClassResolver(), new CubaMapReferenceResolver());
    kryo.setInstantiatorStrategy(new CubaInstantiatorStrategy());
    if (onlySerializable) {
        kryo.setDefaultSerializer(CubaFieldSerializer.class);
    }

    //To work properly must itself be loaded by the application classloader (i.e. by classloader capable of loading
    //all the other application classes). For web application it means placing this class inside webapp folder.
    kryo.setClassLoader(KryoSerialization.class.getClassLoader());

    //noinspection ArraysAsListWithZeroOrOneArgument
    kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
    kryo.register(Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer());
    kryo.register(Collections.EMPTY_MAP.getClass(), new CollectionsEmptyMapSerializer());
    kryo.register(Collections.EMPTY_SET.getClass(), new CollectionsEmptySetSerializer());
    kryo.register(Collections.singletonList("").getClass(), new CollectionsSingletonListSerializer());
    kryo.register(Collections.singleton("").getClass(), new CollectionsSingletonSetSerializer());
    kryo.register(Collections.singletonMap("", "").getClass(), new CollectionsSingletonMapSerializer());
    kryo.register(BitSet.class, new BitSetSerializer());
    kryo.register(GregorianCalendar.class, new GregorianCalendarSerializer());
    kryo.register(InvocationHandler.class, new JdkProxySerializer());
    kryo.register(EnumSet.class, new EnumSetSerializer());
    kryo.register(TreeSet.class, new DefaultSerializers.TreeSetSerializer());
    UnmodifiableCollectionsSerializer.registerSerializers(kryo);
    SynchronizedCollectionsSerializer.registerSerializers(kryo);
    kryo.register(Pattern.class, new RegexSerializer());

    kryo.register(CGLibProxySerializer.CGLibProxyMarker.class, new CGLibProxySerializer());
    ImmutableListSerializer.registerSerializers(kryo);
    ImmutableSetSerializer.registerSerializers(kryo);
    ImmutableMapSerializer.registerSerializers(kryo);
    ImmutableMultimapSerializer.registerSerializers(kryo);
    kryo.register(IndirectList.class, new IndirectContainerSerializer());
    kryo.register(IndirectMap.class, new IndirectContainerSerializer());
    kryo.register(IndirectSet.class, new IndirectContainerSerializer());

    kryo.register(org.eclipse.persistence.indirection.IndirectList.class, new IndirectContainerSerializer());
    kryo.register(org.eclipse.persistence.indirection.IndirectMap.class, new IndirectContainerSerializer());
    kryo.register(org.eclipse.persistence.indirection.IndirectSet.class, new IndirectContainerSerializer());

    //classes with custom serialization methods
    kryo.register(HashMultimap.class, new CubaJavaSerializer());
    kryo.register(ArrayListMultimap.class, new CubaJavaSerializer());
    kryo.register(MetaClassImpl.class, new CubaJavaSerializer());
    kryo.register(MetaPropertyImpl.class, new CubaJavaSerializer());
    kryo.register(UnitOfWorkQueryValueHolder.class, new UnitOfWorkQueryValueHolderSerializer(kryo));

    kryo.addDefaultSerializer(Collection.class, new CubaCollectionSerializer());

    registerEntitySerializer(kryo);

    return kryo;
}
 
Example 11
Source File: KryoSerialization.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected void registerEntitySerializer(Kryo kryo) {
    kryo.addDefaultSerializer(Entity.class, EntitySerializer.class);
}