Java Code Examples for com.esotericsoftware.kryo.Kryo#setDefaultSerializer()
The following examples show how to use
com.esotericsoftware.kryo.Kryo#setDefaultSerializer() .
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 |
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: PropertyUserSerializer.java From subzero with Apache License 2.0 | 5 votes |
private void registerDefaultSerializer(Kryo kryo) { if (defaultSerializerClass != null || !serializerConfigurers.isEmpty()) { Class<? extends Serializer> serializerClass = defaultSerializerClass == null ? FieldSerializer.class : defaultSerializerClass; SerializerFactory serializerFactory = new ReflectionSerializerFactory(serializerClass); if (!serializerConfigurers.isEmpty()) { SerializerConfigurer configurer = serializerConfigurers.get(0); serializerFactory = new PostProcessingSerializerFactory(serializerFactory, configurer); } kryo.setDefaultSerializer(serializerFactory); } }
Example 3
Source File: KryoManager.java From Mundus with Apache License 2.0 | 5 votes |
public KryoManager() { // setup kryo kryo = new Kryo(); kryo.setDefaultSerializer(TaggedFieldSerializer.class); kryo.getTaggedFieldSerializerConfig().setOptimizedGenerics(true); // !!!!! DO NOT CHANGE THIS, OTHERWISE ALREADY SERIALIZED OBJECTS WILL // BE UNREADABLE !!!! // core stuff kryo.register(ArrayList.class, 0); kryo.register(Date.class, 1); kryo.register(RegistryDescriptor.class, 2); kryo.register(ProjectRefDescriptor.class, 3); kryo.register(SettingsDescriptor.class, 4); kryo.register(ProjectSettingsDescriptor.class, 5); kryo.register(KeyboardLayout.class, 6); kryo.register(ProjectDescriptor.class, 7); kryo.register(SceneDescriptor.class, 8); // basic building blocks kryo.register(FogDescriptor.class, 9); kryo.register(GameObjectDescriptor.class, 10); kryo.register(BaseLightDescriptor.class, 11); // components kryo.register(ModelComponentDescriptor.class, 12); kryo.register(TerrainComponentDescriptor.class, 13); }
Example 4
Source File: DbStoragePlainFile.java From Paper with Apache License 2.0 | 5 votes |
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 5
Source File: Namespace.java From atomix with Apache License 2.0 | 5 votes |
/** * 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 6
Source File: KryoNamespace.java From onos with Apache License 2.0 | 5 votes |
/** * 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 7
Source File: KryoSerialization.java From craft-atom with MIT License | 5 votes |
private static Kryo newKryo() { Kryo kryo = new Kryo(); kryo.register(RpcBody.class); kryo.register(RpcMethod.class); kryo.setDefaultSerializer(CompatibleFieldSerializer.class); return kryo; }
Example 8
Source File: KryoContext.java From turbo-rpc with Apache License 2.0 | 4 votes |
public KryoContext() { kryo = new Kryo(new FastClassResolver(), new MapReferenceResolver(), new DefaultStreamFactory()); kryo.setDefaultSerializer(FastSerializer.class); kryo.setReferences(false); kryo.register(ArrayList.class); kryo.register(LinkedList.class); kryo.register(CopyOnWriteArrayList.class); kryo.register(HashMap.class); kryo.register(ConcurrentHashMap.class); kryo.register(TreeMap.class); kryo.register(TreeSet.class); kryo.register(HashSet.class); kryo.register(java.util.Date.class); kryo.register(java.sql.Date.class); kryo.register(LocalDate.class); kryo.register(LocalDateTime.class); kryo.register(byte[].class); kryo.register(char[].class); kryo.register(short[].class); kryo.register(int[].class); kryo.register(long[].class); kryo.register(float[].class); kryo.register(double[].class); kryo.register(boolean[].class); kryo.register(String[].class); kryo.register(Object[].class); kryo.register(BigInteger.class); kryo.register(BigDecimal.class); kryo.register(Class.class); kryo.register(Enum.class); kryo.register(EnumSet.class); kryo.register(Currency.class); kryo.register(StringBuffer.class); kryo.register(StringBuilder.class); kryo.register(Collections.EMPTY_LIST.getClass()); kryo.register(Collections.EMPTY_MAP.getClass()); kryo.register(Collections.EMPTY_SET.getClass()); kryo.register(Collections.singletonList(null).getClass()); kryo.register(Collections.singletonMap(null, null).getClass()); kryo.register(Collections.singleton(null).getClass()); kryo.register(Collection.class); kryo.register(Map.class); kryo.register(TimeZone.class); kryo.register(Calendar.class); kryo.register(Locale.class); kryo.register(Charset.class); kryo.register(URL.class); }
Example 9
Source File: KryoSerialization.java From cuba with Apache License 2.0 | 4 votes |
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 10
Source File: KryoTranscoder.java From hibernate4-memcached with Apache License 2.0 | 4 votes |
/** * Override this method to change serialization rule. * * @return Kryo serializer instance. */ protected Kryo createKryo() { Kryo kryo = new KryoReflectionFactorySupport(); kryo.setDefaultSerializer(CompatibleFieldSerializer.class); return kryo; }