Package com.esotericsoftware.kryo

Examples of com.esotericsoftware.kryo.Serializer


        _componentSerializerFactory = new ComponentSerializerFactory( kryo );
    }

    @Override
    public Serializer newSerializer( final Class<?> type ) {
        Serializer serializer;
        if ( ( serializer = _childListSerializerFactory.newSerializer( type ) ) != null ) {
            return serializer;
        }
        if ( ( serializer = _componentSerializerFactory.newSerializer( type ) ) != null ) {
            return serializer;
View Full Code Here


        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 ) ) {
View Full Code Here

    }
   
    private Serializer loadCustomSerializer( final Class<?> clazz ) {
        if ( _serializerFactories != null ) {
            for( int i = 0; i < _serializerFactories.length; i++ ) {
                final Serializer serializer = _serializerFactories[i].newSerializer( clazz );
                if ( serializer != null ) {
                    if ( LOG.isDebugEnabled() ) {
                        LOG.debug( "Loading custom serializer " + serializer.getClass().getName() + " for class " + clazz );
                    }
                    return serializer;
                }
            }
        }
View Full Code Here

    @Test
    public void test() {
        HibernateCollectionsSerializerFactory factory = new HibernateCollectionsSerializerFactory(new Kryo());

        Serializer serializer = factory.newSerializer(PersistentList.class);
        assertNotNull(serializer);
    }
View Full Code Here

      try {
        if (TRACE) trace("kryo", "Writing field: " + cachedField + " (" + object.getClass().getName() + ")");

        Object value = cachedField.get(object);

        Serializer serializer = cachedField.serializer;

        if (cachedField.fieldClass == null) {
          if (value == null) {
            kryo.writeClass(buffer, null);
            continue;
          }
          RegisteredClass registeredClass = kryo.writeClass(buffer, value.getClass());
          if (serializer == null) serializer = registeredClass.getSerializer();
          serializer.writeObjectData(buffer, value);
        } else {
          if (serializer == null)
            cachedField.serializer = serializer = kryo.getRegisteredClass(cachedField.fieldClass).getSerializer();
          if (!cachedField.canBeNull)
            serializer.writeObjectData(buffer, value);
          else
            serializer.writeObject(buffer, value);
        }
      } catch (IllegalAccessException ex) {
        throw new SerializationException("Error accessing field: " + cachedField + " (" + object.getClass().getName() + ")",
          ex);
      } catch (SerializationException ex) {
View Full Code Here

        if (TRACE) trace("kryo", "Reading field: " + cachedField + " (" + type.getName() + ")");

        Object value;

        Class concreteType = cachedField.fieldClass;
        Serializer serializer = cachedField.serializer;
        if (concreteType == null) {
          RegisteredClass registeredClass = kryo.readClass(buffer);
          if (registeredClass == null)
            value = null;
          else {
            concreteType = registeredClass.getType();
            if (serializer == null) serializer = registeredClass.getSerializer();
            value = serializer.readObjectData(buffer, concreteType);
          }
        } else {
          if (serializer == null)
            cachedField.serializer = serializer = kryo.getRegisteredClass(concreteType).getSerializer();
          if (!cachedField.canBeNull)
            value = serializer.readObjectData(buffer, concreteType);
          else
            value = serializer.readObject(buffer, concreteType);
        }

        cachedField.set(object, value);
      } catch (IllegalAccessException ex) {
        throw new SerializationException("Error accessing field: " + cachedField + " (" + type.getName() + ")", ex);
View Full Code Here

      if (fixedDimensionCount == null) ByteSerializer.putUnsigned(buffer, dimensions.length);
      for (int i = 0, n = dimensions.length; i < n; i++)
        IntSerializer.put(buffer, dimensions[i], true);
    }
    // If element class is final (this includes primitives) then all elements are the same type.
    Serializer elementSerializer = null;
    Class elementClass = getElementClass(array.getClass());
    boolean elementsCanBeNull = this.elementsCanBeNull && !elementClass.isPrimitive();
    if (elementsAreSameType || Modifier.isFinal(elementClass.getModifiers()))
      elementSerializer = kryo.getRegisteredClass(elementClass).getSerializer();
    // Write array data.
View Full Code Here

      for (int i = 0; i < dimensionCount; i++)
        dimensions[i] = IntSerializer.get(buffer, true);
    } else
      dimensionCount = dimensions.length;
    // Get element serializer if all elements are the same type.
    Serializer elementSerializer = null;
    Class elementClass = getElementClass(type);
    boolean elementsCanBeNull = this.elementsCanBeNull && !elementClass.isPrimitive();
    if (elementsAreSameType || Modifier.isFinal(elementClass.getModifiers()))
      elementSerializer = kryo.getRegisteredClass(elementClass).getSerializer();
    // Create array and read in the data.
View Full Code Here

          buffer.position(start + 1);
        } catch (IllegalArgumentException ex) {
          new BufferOverflowException();
        }

        Serializer serializer = cachedField.serializer;
        if (cachedField.fieldClass == null) {
          RegisteredClass registeredClass = kryo.writeClass(buffer, value.getClass());
          if (serializer == null) serializer = registeredClass.getSerializer();
          serializer.writeObjectData(buffer, value);
        } else {
          if (serializer == null)
            cachedField.serializer = serializer = kryo.getRegisteredClass(cachedField.fieldClass).getSerializer();
          if (!cachedField.canBeNull)
            serializer.writeObjectData(buffer, value);
          else
            serializer.writeObject(buffer, value);
        }

        int dataLength = buffer.position() - start - 1;
        if (dataLength <= 127) {
          // Ideally it fits in one byte.
View Full Code Here

        if (dataLength == 0)
          value = null;
        else {
          Class concreteType = cachedField.fieldClass;
          Serializer serializer = cachedField.serializer;
          if (concreteType == null) {
            RegisteredClass registeredClass = kryo.readClass(buffer);
            if (registeredClass == null)
              value = null;
            else {
              concreteType = registeredClass.getType();
              if (serializer == null) serializer = registeredClass.getSerializer();
              value = serializer.readObjectData(buffer, concreteType);
            }
          } else {
            if (serializer == null)
              cachedField.serializer = serializer = kryo.getRegisteredClass(concreteType).getSerializer();
            if (!cachedField.canBeNull)
              value = serializer.readObjectData(buffer, concreteType);
            else
              value = serializer.readObject(buffer, concreteType);
          }
        }

        cachedField.set(object, value);
      } catch (IllegalAccessException ex) {
View Full Code Here

TOP

Related Classes of com.esotericsoftware.kryo.Serializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.