}
private Triple<Kryo, SerializerFactory[], UnregisteredClassHandler[]> createKryo( final ClassLoader classLoader,
final String[] customConverterClassNames, final boolean copyCollectionsForSerialization ) {
final Kryo kryo = new KryoReflectionFactorySupport() {
@Override
@SuppressWarnings( { "rawtypes", "unchecked" } )
public Serializer newSerializer(final Class clazz) {
final Serializer customSerializer = loadCustomSerializer( clazz );
if ( customSerializer != null ) {
return customSerializer;
}
if ( EnumSet.class.isAssignableFrom( clazz ) ) {
return new EnumSetSerializer( this );
}
if ( EnumMap.class.isAssignableFrom( clazz ) ) {
return new EnumMapSerializer( this );
}
if ( SubListSerializer.canSerialize( clazz ) ) {
return new SubListSerializer( this, clazz );
}
if ( copyCollectionsForSerialization ) {
final Serializer copyCollectionSerializer = loadCopyCollectionSerializer( clazz, this );
if ( copyCollectionSerializer != null ) {
return copyCollectionSerializer;
}
}
if ( Date.class.isAssignableFrom( clazz ) ) {
return new DateSerializer( clazz );
}
return super.newSerializer( clazz );
}
@SuppressWarnings( { "rawtypes" } )
@Override
protected void handleUnregisteredClass( final Class clazz ) {
if ( _unregisteredClassHandlers != null ) {
for( int i = 0; i < _unregisteredClassHandlers.length; i++ ) {
final boolean handled = _unregisteredClassHandlers[i].handleUnregisteredClass( clazz );
if ( handled ) {
if ( LOG.isDebugEnabled() ) {
LOG.debug( "UnregisteredClassHandler " + _unregisteredClassHandlers[i].getClass().getName() + " handled class " + clazz );
}
return;
}
}
}
super.handleUnregisteredClass( clazz );
}
@Override
protected Serializer newDefaultSerializer( @SuppressWarnings( "rawtypes" ) final Class type ) {
return _defaultSerializerFactory.newDefaultSerializer( this, type );
}
};
if ( classLoader != null ) {
kryo.setClassLoader( classLoader );
}
// com.esotericsoftware.minlog.Log.TRACE = true;
kryo.setRegistrationOptional( true );
kryo.register( ArrayList.class );
kryo.register( LinkedList.class );
kryo.register( HashSet.class );
kryo.register( HashMap.class );
kryo.register( Arrays.asList( "" ).getClass(), new ArraysAsListSerializer( kryo ) );
kryo.register( Currency.class, new CurrencySerializer( kryo ) );
kryo.register( StringBuffer.class, new StringBufferSerializer( kryo ) );
kryo.register( StringBuilder.class, new StringBuilderSerializer( kryo ) );
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 ) );
kryo.register( Collections.singleton( "" ).getClass(), new CollectionsSingletonSetSerializer( kryo ) );
kryo.register( Collections.singletonMap( "", "" ).getClass(), new CollectionsSingletonMapSerializer( kryo ) );
kryo.register( Class.class, new ClassSerializer( kryo ) );
kryo.register( BigDecimal.class, new BigDecimalSerializer() );
kryo.register( BigInteger.class, new BigIntegerSerializer() );
kryo.register( GregorianCalendar.class, new GregorianCalendarSerializer() );
kryo.register( InvocationHandler.class, new JdkProxySerializer( kryo ) );
UnmodifiableCollectionsSerializer.registerSerializers( kryo );
SynchronizedCollectionsSerializer.registerSerializers( kryo );
kryo.register( Locale.class, new LocaleSerializer() );
final Triple<KryoCustomization[], SerializerFactory[], UnregisteredClassHandler[]> pair = loadCustomConverter( customConverterClassNames,
classLoader, kryo );
final KryoCustomization[] customizations = pair.a;