com.esotericsoftware.kryo.util.DefaultClassResolver Java Examples

The following examples show how to use com.esotericsoftware.kryo.util.DefaultClassResolver. 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: KryoFactory.java    From vertexium with Apache License 2.0 6 votes vote down vote up
public Kryo createKryo() {
    Kryo kryo = new Kryo(new DefaultClassResolver(), new MapReferenceResolver() {
        @Override
        public boolean useReferences(Class type) {
            // avoid calling System.identityHashCode
            if (type == String.class || type == Date.class) {
                return false;
            }
            return super.useReferences(type);
        }
    });
    registerClasses(kryo);

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

    return kryo;
}
 
Example #2
Source File: KryoPool.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Kryo newInstance() {
    Kryo next = new Kryo(new DefaultClassResolver(),new MapReferenceResolver());
    if(kryoRegistry!=null)
        kryoRegistry.register(next);
    return next;
}
 
Example #3
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;
}