Giter Site home page Giter Site logo

kryo's People

Contributors

magro avatar opti-mix avatar

kryo's Issues

Not able to Serialize a class which had EnumSet as a member variable.

What steps will reproduce the problem?
1. Register a class which has EnumSet in it
2.
3.

What is the expected output? What do you see instead?

Caused by: java.lang.IllegalArgumentException: Class is not registered: 
java.util.RegularEnumSet
    at com.esotericsoftware.kryo.Kryo.getRegisteredClass(Kryo.java:311)
    at com.esotericsoftware.kryo.Kryo.writeClass(Kryo.java:366)
    at com.esotericsoftware.kryo.serialize.FieldSerializer.writeObjectData(FieldSerializer.java:165)
    ... 3 more

What version of the Kryo are you using?
1.03


Please provide any additional information below.
RegularEnumSet is not public so not able to register I could register EnumSet 
but not working.


Original issue reported on code.google.com by [email protected] on 30 Sep 2010 at 4:53

final fields should be handled by FieldSerializer if setFieldsAsAccessible is set to true

The FieldSerializer right now does not handle final fields. It should do so if 
setFieldsAsAccessible is set to true 
(default). As an alternative, it would be nice to have the possible to have 
s.th. like 
setSupportFinalFields(boolean).

Attached is a patch for FieldSerializer that checks setFieldsAsAccessible and 
does not skip the field if 
setFieldsAsAccessible is true.

Original issue reported on code.google.com by martin.grotzke on 5 Apr 2010 at 9:10

Attachments:

Internal Class Version in Bytecode Generated Classes

The generated classes with ASM should have the internal version compatible with 
the JVM that runs the code. Actually, is fixed in the 1.6 version.

This is not a big problem (maybe only we still running our products in 1.5 
only), but maybe should say something about "for JRE 1.6+" somewhere in the 
documentation.

Thanks.


Original issue reported on code.google.com by [email protected] on 24 Nov 2010 at 8:20

Enums with Method definitions

What steps will reproduce the problem?
1. Create an Enum A where the constant values have method definitions. Create a 
class B with a public field of type A.
2.Instantiate B and serialize it where handling of unregistered classes is 
enabled.
3.Deserialize it.

What is the expected output? What do you see instead?
The expected output is that the original output gets recovered. Instead, a null 
pointer exception is thrown (which gets re-thrown as a serialization exception.

What version of the Kryo are you using?
I tried this with 1.03 and the current head of trunk.

Please provide any additional information below.

For Enums where the constant values have method definitions, Java assigns each 
enumeration value its own inner class. For an Enum A with values "One" and 
"Two", the class of A.One would be A$1. This seems to cause trouble with Kryo. 
When registration is mandatory, Kryo will fail on serialization because A$1 has 
not been registered even though A has. But even if I register A.One and A.Two 
explicitly, this still causes trouble inside the FieldSerializer for objects 
that use this enum as a field type.

Maybe using the declaring class of an enum constant (i.e. 
A.One.getDeclaringClass()) rather than getClass() would solve the problem.

Example stack trace:
com.esotericsoftware.kryo.SerializationException: Unable to deserialize object 
of type: edu.umd.umiacs.dogma.diskgraph.serializer.test.TestClass
    at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:596)
    at edu.umd.umiacs.dogma.diskgraph.serializer.test.SerializerUnitTest.objectWriteRead(SerializerUnitTest.java:52)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: com.esotericsoftware.kryo.SerializationException: Serialization 
trace:
e (edu.umd.umiacs.dogma.diskgraph.serializer.test.TestClass)
    at com.esotericsoftware.kryo.serialize.FieldSerializer.readObjectData(FieldSerializer.java:237)
    at com.esotericsoftware.kryo.serialize.FieldSerializer.readObjectData(FieldSerializer.java:199)
    at com.esotericsoftware.kryo.Serializer.readObject(Serializer.java:61)
    at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:592)
    ... 25 more
Caused by: java.lang.NullPointerException
    at com.esotericsoftware.kryo.serialize.EnumSerializer.readObjectData(EnumSerializer.java:24)
    at com.esotericsoftware.kryo.serialize.FieldSerializer.readObjectData(FieldSerializer.java:219)
    ... 28 more

Original issue reported on code.google.com by [email protected] on 28 Jan 2011 at 2:42

Deserialization of SomeIFace[] with Enum as impl of SomeIFace fails

The attached ArraySerializerTest fails with 
java.lang.IllegalArgumentException: array element type mismatch
    at java.lang.reflect.Array.set(Native Method)
    at 
com.esotericsoftware.kryo.serialize.ArraySerializer.readArray(ArraySerializ
er.java)

Just place the ArraySerializerTest in 
test/com/esotericsoftware/kryo/serialize and execute.

I ran it against the kryo trunk (rev 108).

We have such a combination of an interface-array and enum implementations, 
so this is a real issue for us.

Original issue reported on code.google.com by martin.grotzke on 25 May 2010 at 10:44

Attachments:

Build Kryo 1.04

Hello,

i want to build kryo 1.04 as maven project.
The problem is that in the pom.xml the version is 1.1-SNAPSHOT and
if i want to build this it returns:
The following artifacts could not be resolved: 
com.esotericsoftware:reflectasm:jar:0.8, com.esotericsoftware:minlog:jar:1.2

Were can i get this artifacts? The tags i can find are in the wrong version. I 
need this as maven project in svn or git.

Original issue reported on code.google.com by [email protected] on 18 Nov 2011 at 8:56

not all fields are correctly serialized

fields with the modifier final should be serialized, as they can contain
runtime data. Same goes to static fields

class Foo {
    static int count = 0;
    final int ID;

    public Foo() {
        ID = count++;
    }
}


the only fields not needed to be serialized are: "transient", "static final"


Original issue reported on code.google.com by [email protected] on 30 Nov 2009 at 3:36

  • Merged into: #15

IllegalArgumentException thrown using CompatibleFieldSerializer during deserialization

What steps will reproduce the problem?
No problems in serializing / deserializing using a default FieldSerializer. 
Uisng the CompatibleFieldSerializer serializing / deserializing round-trips 
work for shallow graphs but for deeply nested collections the round-trip fails 
by throwing an IllegalArgumentException ( usually during deserialization and 
when passing a null value to a primitive value field ). Cant tell if its the 
deserialization thats broken or the serialized stream is incomplete / wrong.

Registering the classes to use the CompatibleFieldSerializer remedies the 
problem in some cases ( such as the example attached ) but in others it has no 
effect ( not attached ).

What is the expected output? What do you see instead?
Expected round trip serializing / deserializing to produce equivalent objects - 
instead the test case attached errors out when using CompatibleFieldSerializer 

What version of the Kryo are you using?
1.03

Please provide any additional information below.
Attached test case and MultiMap / aggregate object to reproduce the error


Original issue reported on code.google.com by [email protected] on 22 Dec 2010 at 6:16

Attachments:

Unable to deserialize with CompatibleFieldSerializer

What steps will reproduce the problem?
1. Create any class with an enum field
2. Register the class and enum in step 1 with CompatibleFieldSerializer
3. Serialize the class and deserialize it with CompatibleFieldSerializer

What is the expected output? What do you see instead?

Expected output: the object should be deserialized correctly

Received exception:

Class cannot be created (missing no-arg constructor): 
test.KryoBackwardCompatiblityTest$TestEnumSer
Serialization trace:
testEnum (test.KryoBackwardCompatiblityTest$AModel)
    at com.esotericsoftware.kryo.Kryo.newInstance(Kryo.java:688)
    at com.esotericsoftware.kryo.Serializer.newInstance(Serializer.java:75)
    at com.esotericsoftware.kryo.serialize.CompatibleFieldSerializer.readObjectData(CompatibleFieldSerializer.java:215)
    at com.esotericsoftware.kryo.Serializer.readObject(Serializer.java:61)
    at com.esotericsoftware.kryo.serialize.CompatibleFieldSerializer.readObjectData(CompatibleFieldSerializer.java:283)
    at com.esotericsoftware.kryo.serialize.CompatibleFieldSerializer.readObjectData(CompatibleFieldSerializer.java:215)
    at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:566)


What version of the Kryo are you using?

1.03 
1.04

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 3 May 2011 at 6:45

Optimization for objectbuffer

Hi - 

One suggestion to improve performance of ObjectBuffer on large objects (when at 
runtime its unknown that they're large, so the buffer's initial capacity is 
low) -- Is it possible for the buffer to determine by how much its 
underallocated when it finds that its max capacity is insufficient?  E.g. in 
our case we're Kryoing an object that contains a byte[], and the byte[] is very 
large, but it should be possible for Kryo to know how much extra room it needs, 
and rather than just double the capacity, it could keep doubling until it the 
new allocated amount meets the new allocation requirement.

Hope that makes sense

Thanks! 

Original issue reported on code.google.com by [email protected] on 9 Mar 2011 at 12:28

"Can not set field to java.lang.Boolean"

Using Kryonet we're having a bit of trouble when moving large-ish objects over 
a network connection. The error does not happen when connecting to localhost, 
only when connecting to a remote computer.

The error itself comes from the depths of Kryo where, for some reason, Kryo is 
trying to set a field of non-Boolean type to a Boolean value. The particular 
field which it tries to set is not always the same, either.

Any ideas on why this might be happening?

Using Kryo/Kryonet v1.04.

Original issue reported on code.google.com by [email protected] on 25 Nov 2011 at 3:02

Serializes items that can't be deserialized

What steps will reproduce the problem?
1. Register a number of classes with Kryo, including 'Class.class'
2. Serialize something containing a Class as a field with Kryo
3. Deserialize with Kryo

What is the expected output? What do you see instead?
We'd expect that it would fail serializing given that it won't be able to 
deserialize due to the 'newInstance' constraint w/ Class.  Instead it 
serializes just fine, but a VM with the same registration properties as the 
current one can't deserialize it.


What version of the Kryo are you using?
Latest


Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 20 Dec 2010 at 5:23

BufferOverflowException

What steps will reproduce the problem?
1.create a bean class, holding a reference to another one, like 
     public class Dinner
     {
    private Dinner next;

    public Dinner getNext()
    {
        return next;
    }

    public void setNext(Dinner next)
    {
        this.next = next;
    }   
     }
2.instantiate one and set the next to itself,
     Dinner d = new Dinner();
     d.setNext(d);
3.Use kryo ( version 1.01 ) to serialize it,
     byte[] bytes = buffer.writeObjectData(src);

   You will get the BufferOverflowException for sure.


Original issue reported on code.google.com by [email protected] on 8 Mar 2011 at 6:00

  • Merged into: #8

infinite loop when child object reference parent

It looks like kryo cannot serialize objects with cyclic reference :

class Parent {
    List<Child> children;
}

class Child {
    Parent parent;
}

Do you think kryo can support those objects some day ?

Thanx

Original issue reported on code.google.com by [email protected] on 28 Oct 2009 at 7:03

  • Merged into: #7

Deserializing a class with transient field that requires deserialization of another class

I have a class B which contains a transient field that its initialization 
requires deserialization of class A. Trying to deserialize class B completely 
breaks Kryo (running a single thread). I thought that maybe calling 
'Kryo.getContext().reset()' would solve the issue but that didn't help.

What steps will reproduce the problem?

  Run the attached code (also given below).

What is the expected output? What do you see instead?

  I expect the program to end successfully. Instead I get an exception.

What version of the Kryo are you using?

  1.04

Please provide any additional information below.

  The code to reproduce the problem:


-------------------------------------------------------------------

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Vector;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.ObjectBuffer;

public class Main {

    public static <T> void serialize(T obj, String filename) throws FileNotFoundException, IOException
    {
        Kryo kryo = new Kryo();
        kryo.setRegistrationOptional(true);
        //Kryo.getContext().reset();
        ObjectBuffer buffer = new ObjectBuffer(kryo, 100000);
        OutputStream os = new FileOutputStream(filename);
        buffer.writeClassAndObject(os, obj);
        os.close();
    }

    @SuppressWarnings("unchecked")
    public static <T> T deserialize(String filename) throws IOException, ClassNotFoundException
    {
        Kryo kryo = new Kryo();
        kryo.setRegistrationOptional(true);
        //Kryo.getContext().reset();        
        InputStream is = new FileInputStream(filename);
        ObjectBuffer buffer = new ObjectBuffer(kryo, 100000);
        Object obj = buffer.readClassAndObject(is);
        is.close();
        return (T) obj;
    }


    public static class Class1
    {
        private Vector<float[]> values = new Vector<float[]>();
        public Class1() {
            for(int i=0; i < 2; ++i) values.add(new float[i+1]);
        }
        public float[] getValue(int i) { return values.get(i); }
    }

    public static class Class2
    {
        private Map<String, Vector<LinkedList<Float>>> data = new HashMap<String, Vector<LinkedList<Float>>>();
        private transient Class1 class_1 = readClass1();
        public Class2() {

            Vector<LinkedList<Float>> value1 = new Vector<LinkedList<Float>>();
            value1.add(new LinkedList<Float>());
            value1.lastElement().add(1.1f);
            value1.lastElement().add(1.2f);
            value1.add(new LinkedList<Float>());
            value1.lastElement().add(2.1f);
            value1.lastElement().add(2.2f);

            Vector<LinkedList<Float>> value2 = new Vector<LinkedList<Float>>();
            value2.add(new LinkedList<Float>());
            value2.lastElement().add(1.1f);
            value2.lastElement().add(1.2f);
            value2.add(new LinkedList<Float>());
            value2.lastElement().add(2.1f);
            value2.lastElement().add(2.2f);
            value2.add(new LinkedList<Float>());
            value2.lastElement().add(3.1f);
            value2.lastElement().add(3.2f);

            data.put("key1", value1);
            data.put("key2", value2);
        }
        public float[] getValue() { return class_1.getValue(1); }

        private Class1 readClass1()
        {
            try {
                return deserialize("d:/test_java_class_1.dat");
            } catch (Exception e) {
                throw new Error("Can't deserialize !", e);
            }
        }
    }


    public static void main(String[] args) throws Exception
    {
        com.esotericsoftware.minlog.Log.TRACE = true;

        Class1 base = new Class1();
        serialize(base, "d:/test_java_class_1.dat");
        Class2 one = new Class2();
        System.out.println(one.getValue().length);
        serialize(one, "d:/test_java_class_2.dat");
        Class2 two = deserialize("d:/test_java_class_2.dat");
        System.out.println(two.getValue().length);
    }

}


Original issue reported on code.google.com by [email protected] on 14 Feb 2012 at 11:49

Attachments:

Can't figure out how to get rid of some loggings

What steps will reproduce the problem?
1. file read
2. kryo.register(MarketData.class, new DeltaCompressor(kryo, new 
FieldSerializer(kryo, MarketData.class)));
3. buffer.writeObject(fileOutputStream, o);

What is the expected output? What do you see instead?
no logging

I see:
compress APPEND 10: -64,-115,-73,1,-14,-59,-119,-105,-127,66,
compress APPEND 29: 
63,-26,92,-111,-47,78,59,-51,-96,-128,-79,1,63,-26,90,28,-84,8,49,39,-64,-124,61
,-56,-35,-119,-105,-127,66,
compress COPY at 0, length 14: 
63,-26,92,-111,-47,78,59,-51,-96,-128,-79,1,63,-26,

What version of the Kryo are you using?
1.03

Actually it's not minlog logs, in code there are system.outs, and some debug 
boolean, do I have to set it to false somehow?

Original issue reported on code.google.com by [email protected] on 27 Sep 2010 at 10:07

Accessing non-public fields with bytecode

This is not an issue but rather a proposal.

You write that you use generated bytecode to access public fields and cached 
reflection to access protected and private fields.

I propose that you use bytecode corresponding to the example below to also 
access protected fields (and with a variant also package visible fields) but 
improved speed.


// an existing class with a non-private field x:
class Existing {
    protected byte x;
}

// a serializer which *can* access x within java rules:
class Serializer extends Existing {
    public static void writeObject(final ByteBuffer b, final Existing t) {
        b.put(t.x);
    }
}

The idea is to create a class which inherits from the class in question (which 
allows to access the field) but not to use instances of that class (we have no 
use for it anyway).

Accessing package visible fields is also possible with a variant of this method 
- provided the package is not protected by the SecurityManager. Just generate a 
class in that package. 

Looking at your code I think that a fairly straitforward variant or your 
MethodAccess code should do it. 

Accessing private fields is of course no possible with this approach as that 
would require geenrating access code *in* the class at question which is not 
possible *after* that class is loaded.

In the long run you might consider providing a ClassLoader which intercepts 
class load calls and adds special custom serialization methods in all classes 
of your choice. Then you'd only need to call those methods during serialization.

Yours

Gunnar Zarncke

Original issue reported on code.google.com by [email protected] on 2 Sep 2010 at 2:55

StackOverflowError when serializing set containing itself

What steps will reproduce the problem?
1. public class CyclicSet {
    public Set set = new HashSet();
    {
        set.add(set);
    }
   }   
2. Then just try to serialize new CyclicSet() 


What is the expected output? What do you see instead?

 I expect this object to be serialized.

What version of the Kryo are you using?

 1.03

Original issue reported on code.google.com by chaschev on 17 Nov 2010 at 2:37

Feature: Print object graph when serialization fails

When serialization fails it would be really helpfull to get the object graph 
printed to get an idea of potential issues.

Original issue reported on code.google.com by martin.grotzke on 11 Aug 2010 at 9:02

  • Merged into: #21

Compressor cannot handle large graphs

Compressor only uses a short to store the length of the compressed data (lines 
78 and 91).  This cannot be easily changed by subclasses either, since the 
length is written in the parent class.

I altered Compressor to use int, and was able to successfully retrieve my data.

Original issue reported on code.google.com by [email protected] on 8 Sep 2011 at 2:44

It is not possible to serialize classes without a zero-argument-constructor

What steps will reproduce the problem?
1. generate a class without default constructor
2. serialize it with kryo

What is the expected output? What do you see instead?
expected: no output
output: Exceptions about missing zero-argument constructor

What version of the product are you using? On what operating system?
0.92



why not using the internal way of creating an empty object?
example source attached



Original issue reported on code.google.com by [email protected] on 30 Nov 2009 at 3:04

Attachments:

Support concurrent access of Kryo.register

When Kryo is used in a multi-threaded environment external synchronization is 
required to ensure that the internally used HashMap classToRegisteredClass (and 
probably the IntHashMap idToRegisteredClass) cannot be broken which might cause 
infinite loops.

The suggested patch now synchronizes write access of classToRegisteredClass on 
exactly this object. From my understanding this is enough to ensure that the 
HashMap internal linked lists cannot be broken. As read access is not 
synchronized it might happen that some thread gets an "invalid" object from the 
map that is replaced by a second thread, but IMHO this isn't an issue as 
correct functionality/behavior is not affected by this.

As the synchronized block on classToRegisteredClass also included the 
idToRegisteredClass.put, I think this potential concurrency issue is also 
solved.

Is this patch acceptable? Can you apply it as soon as possible and make a new 
release? This would save the world for me right now :-)

Original issue reported on code.google.com by martin.grotzke on 8 Sep 2010 at 1:05

Attachments:

2D arrays are incorrectly (de)serialized

What steps will reproduce the problem?
1. Run the following code:
public static void main(String[] args)
  {
    Kryo kryo = new Kryo();
    kryo.setRegistrationOptional(true);
    ByteBuffer buffer = ByteBuffer.allocate(1024);

    float[][] array = new float[4][];
    array[0] = new float[]{0.0f,1.0f};
    array[1] = null;
    array[2] = new float[]{2.0f,3.0f};
    array[3] = new float[]{3.0f};
    print(array,"Original array:");

    kryo.writeClassAndObject(buffer, array);
    buffer.rewind();
    Object o = kryo.readClassAndObject(buffer);
    float[][] array_ = (float[][])o;
    print(array_,"Deserialized array:");
  }

  static void print(float[][] array, String header)
  {
    System.out.println(header);
    for(int i=0;i<array.length;i++)
    {
      System.out.println(Arrays.toString(array[i]));
    }
    System.out.println();
  }

I get this:
Original array:
[0.0, 1.0]
null
[2.0, 3.0]
[3.0]

Deserialized array:
[0.0, 1.0]
[2.0, 3.0]
[3.0, 0.0]
[0.0, 0.0]

What is the expected output? What do you see instead?
I expect the data to be deserialized into array with the same data.
Deserialized array should be the same as Original array, but it isn't.

What version of the Kryo are you using?
1.04

Please provide any additional information below.
With 1.02 I had an ArrayOutOfBoundsException in not the same, but similar 
situation.

Original issue reported on code.google.com by [email protected] on 3 Mar 2011 at 7:18

Buffer Allocation Fails when using Integer.MAX_VALUE

What steps will reproduce the problem?
1. Use an ObjectBuffer with a max allocation of Integer.MAX_VALUE
2. Try allocate a very large object
3. On the last increment of trying to double the buffer, the line that has int 
newCapacity = Math.min(maxCapacity, capacity * 2) results in a negative value 
because capacity*2 flips to negative.

What is the expected output? What do you see instead?
It should take maxCapacity over a negative value


What version of the Kryo are you using?
1.03


Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 6 Mar 2011 at 1:34

Wrong buffer contents (bytes) when using ObjectBuffer to read object data

Detailed Problem Description:

The issue appears when the ObjectBuffer is created with an initial capacity
that is lower than the object data to read. (If the initial capacity is
greater than the size of the object to read, the issue does not appear).

The source of the problem seems to reside in the resizeBuffer method in the
following statement:
if (preserveContents) newBuffer.put(buffer);

newBuffer.put only transfers the REMAINING bytes of buffer (the source
buffer). I think the statement should be corrected to:
if (preserveContents) {
  buffer.position(0);
  newBuffer.put(buffer);
}

What is the expected output? What do you see instead?
Without the fix above I get a wrong sequence of bytes due to copying only
remaining bytes when resizing the buffer.


What version of the Kryo are you using?
Version 1.0



Original issue reported on code.google.com by [email protected] on 23 Mar 2010 at 8:18

CompatibleSerializer deserializes wrongly if subclass has the same field as super class

What steps will reproduce the problem?
1. Run the code attached.
   jvm arg:  -Djava.io.tmpdir=<tempdir to stored the output file>

   //For default FieldSerializer
   test.withDefault(); 

   //For CompatibleFieldSerializer
   test.withCompatibleFieldSerializer;


2.  If the file is not there it will serialize a sample object to a file and 
save it to tempdir.
    If the file has already existed, the program will deserialize it.

3.

What is the expected output? What do you see instead?

//Output with default FieldSerializer: 
class[class 
com.scb.saturn.services.position.NewKryoTest$ChildModel];field1[f1];field2[f2];l
ongField[25];

//Output with CompatibleFieldSerializer:
class[class 
com.scb.saturn.services.position.NewKryoTest$ChildModel];field1[f1];field2[f2];l
ongField[0];

Expected the same output from both FieldSerializer and CompatibleFieldSerializer


What version of the Kryo are you using?
1.04

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 4 May 2011 at 7:33

Attachments:

Memory consumption

Any use of the library requires one to know the size of the serialized
object which is not always true. Allocating 10 MB per thread in a server
setting just "to be sure" is not ideal.

For instance:
Kryo kryo = new Kryo();
kryo.setAllowUnregisteredClasses(true);
ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024 * 10);
kryo.writeClassAndObject(buffer, "This is a test");

What is the expected output? What do you see instead?

I would expect a version of ther API to work with Outputstream for writing
and InputStream for reading, not ByteBuffer.

For instance:
Kryo kryo = new Kryo();
kryo.setAllowUnregisteredClasses(true);
OutputStream outputStream = ...
kryo.writeClassAndObject(outputStream, "This is a test");

What version of the product are you using? On what operating system?
Kryo 1.0 on Ubuntu 9.10 & Win7

If there is not requirement for reading the buffer after the data is
written to it, this should be simple to fix, perhaps by adding a thin
wrapper to allow your API to accept ByteBuffer, InputStream/OutputStream, etc. 

So I guess this boils down to: 
Do you read back the buffer contents after you have started serializing an
object?

Thanks for your time! :) 

Original issue reported on code.google.com by [email protected] on 20 Mar 2010 at 1:29

Weak References to Class files

This is a very preliminary rough patch.  I have some other ideas that I'd
also like to experiment, I've posted it here so others may experiment with
it also.

New BSD License as per Kryo.

This builds and all the tests pass, note that this patch is set to weak
references in Kryo's constructor by default.

You've got some performance testing code also I believe?

Cheers,

Peter.

Original issue reported on code.google.com by [email protected] on 13 Apr 2010 at 10:42

Attachments:

Zip archive does not expand into a directory

It is convention to zip a directory so that on expansion you get a directory. 
Instead I got the contents of the kryo directory sprayed across my working area 
which I then had to go an clean up manually.


What steps will reproduce the problem?
1.unzip kryo.zip

What version of the Kryo are you using?
kryo-1.0.3

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 31 Dec 2010 at 1:14

Public final fields are being set through ASM instead of reflection in FieldSerializer

What steps will reproduce the problem?
1. Create and serialize a class with a public final field
2. Try to deserialize it

What is the expected output? What do you see instead?

A java.lang.IllegalAccessError is thrown when the ASM-generated helper class 
tries to set the field's value.

One would expect the changes in issue #15 to call setAccessible on the field, 
but because the field gets put into the publicFields array list in 
FieldSerializer.rebuildCachedFields, it is handled with ASM regardless of the 
fact that it's final.

What version of the Kryo are you using?

1.03

Please provide any additional information below.

The fix is very simple -- in the if statement in FieldSerializer.java that adds 
elements to publicFields (line 99 in Kryo 1.03), add the condition 
!Modifier.isFinal(modifiers).

Original issue reported on code.google.com by [email protected] on 9 Nov 2010 at 7:49

Cann't read serialized ArrayList or HashMap

What steps will reproduce the problem?
        Kryo kryo = new Kryo();
        kryo.register(ArrayList.class);
        //TestClass stc = new TestClass();
        ArrayList al = new ArrayList(Arrays.asList("1", "2", "3"));
        ByteBuffer buffer = ByteBuffer.allocate(1024);

        kryo.writeObject(buffer,al); 
        buffer.flip();      
        ArrayList stc1 = kryo.readObject(buffer, ArrayList.class);
        System.out.println(stc1.get(1));
What is the expected output? What do you see instead?
Exception is java.nio.BufferUnderflowException

What version of the product are you using? On what operating system?

0.92, XP SP2 and jdk 1.6
Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 9 Nov 2009 at 3:05

ByteArrayCompressor.compress() allocates byte array that is too short if input buffer length > 2048

In Kryo 1.0, when ByteArrayCompressor.compress() is passed an inputBuffer 
that contains more than 2048 bytes to be compressed, it throws an 
IndexOutOfBoundsException.

Here's the code.

public void compress (ByteBuffer inputBuffer, Object object, ByteBuffer 
outputBuffer) {
    Context context = Kryo.getContext();                        // 1
    byte[] inputBytes = context.getBuffer(bufferSize).array();  // 2
    int inputLength = inputBuffer.remaining();                  // 3
    inputBuffer.get(inputBytes, 0, inputLength);                // 4
    compress(inputBytes, inputLength, outputBuffer);            // 5
}

The problem is that line 2 will normally return a byte array that is only 
2048 bytes long and line 4 will throw an exception if the 'inputBytes' 
array is shorter than 'inputLength'.

Original issue reported on code.google.com by [email protected] on 22 Apr 2010 at 7:45

ReferenceFieldSerializerTest failure: non static inner class

Hi Nate,

I've checked out the latest revision of kryo from svn and built using
Netbeans 6.0.1

$ uname -a
SunOS bluto 5.10 Generic_137111-06 sun4u sparc SUNW,Ultra-80

$ java -version
java version "1.6.0_07"
Java(TM) Platform, Standard Edition for Business (build 1.6.0_07-b06)
Java HotSpot(TM) Server VM (build 10.0-b23, mixed mode)

These are the failure results, all other tests are passing:

Testsuite: com.esotericsoftware.kryo.serialize.ReferenceFieldSerializerTest
Tests run: 5, Failures: 2, Errors: 0, Time elapsed: 1.028 sec

Testcase:
testNonStaticInnerClassPublicConstructor(com.esotericsoftware.kryo.serialize.Ref
erenceFieldSerializerTest):
FAILED
Incorrect length. expected:<18> but was:<15>
junit.framework.AssertionFailedError: Incorrect length. expected:<18> but
was:<15>
        at
com.esotericsoftware.kryo.KryoTestCase.roundTripKryo(KryoTestCase.java:86)
        at
com.esotericsoftware.kryo.KryoTestCase.roundTrip(KryoTestCase.java:74)
        at
com.esotericsoftware.kryo.serialize.ReferenceFieldSerializerTest.testNonStaticIn
nerClassPublicConstructor(ReferenceFieldSerializerTest.java:76)


Testcase:
testNonStaticInnerClassPrivateConstructor(com.esotericsoftware.kryo.serialize.Re
ferenceFieldSerializerTest):
FAILED
Incorrect length. expected:<18> but was:<15>
junit.framework.AssertionFailedError: Incorrect length. expected:<18> but
was:<15>
        at
com.esotericsoftware.kryo.KryoTestCase.roundTripKryo(KryoTestCase.java:86)
        at
com.esotericsoftware.kryo.KryoTestCase.roundTrip(KryoTestCase.java:74)
        at
com.esotericsoftware.kryo.serialize.ReferenceFieldSerializerTest.testNonStaticIn
nerClassPrivateConstructor(ReferenceFieldSerializerTest.java:91)


Test com.esotericsoftware.kryo.serialize.ReferenceFieldSerializerTest FAILED

Original issue reported on code.google.com by [email protected] on 12 Apr 2010 at 7:52

Problem with deflate - wrong result?

What steps will reproduce the problem?
1. Run the attached program

What is the expected output? What do you see instead?
Expected: Same hash code for original object and de-serialized object
Actual: Different hash codes

What version of the Kryo are you using?
1.01

Please provide any additional information below:
The application works (although the serialized size is mucgh larger than
for Java serialization) when no compression is used.
All the deserialized HashSets seem to be empty when compression is used.

-------------------------------------------

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.compress.DeflateCompressor;
import com.esotericsoftware.kryo.serialize.FieldSerializer;

import java.io.*;
import java.nio.ByteBuffer;
import java.util.*;


public class Serializer {

    public static void close(final Closeable closeable) {
        if (closeable != null)
            try {
                closeable.close();
            } catch (IOException e) {
                // ignore
            }
    }

    public static byte[] serialize(final Serializable serializable)
            throws IOException {
        ByteArrayOutputStream os = null;
        BufferedOutputStream bos = null;
        ObjectOutputStream oos = null;
        try {
            os = new ByteArrayOutputStream();
            bos = new BufferedOutputStream(os);
            oos = new ObjectOutputStream(bos);
            oos.writeObject(serializable);
            oos.flush();
            bos.flush();
            os.flush();
            return os.toByteArray();
        } finally {
            CloseHelper.close(oos);
            close(bos);
            close(os);
        }
    }

    public static Serializable deserialize(final byte[] serialized)
            throws IOException {
        ByteArrayInputStream bais = null;
        BufferedInputStream bis = null;
        ObjectInputStream ois = null;
        try {
            bais = new ByteArrayInputStream(serialized);
            bis = new BufferedInputStream(bais);
            ois = new ObjectInputStream(bis);
            try {
                return (Serializable) ois.readObject();
            } catch (ClassNotFoundException e) {
                throw new IllegalStateException("Failed to create object!", e);
            }
        } finally {
            close(ois);
            close(bis);
            close(bais);
        }
    }

    private static Serializable buildStructure(int size) {
        Random random = new Random(123456789);
        ArrayList<Set<Object>> objects = new ArrayList<Set<Object>>();
        for (int i = 0; i < size; i++) {
            Set<Object> set = new HashSet<Object>();
            // Add some data
            final int numberOfIntegers = random.nextInt(5);
            for (int integers = 0; integers < numberOfIntegers; integers++)
                set.add(random.nextInt(10000));
            final int numberOfDoubles = random.nextInt(5);
            for (int doubles = 0; doubles < numberOfDoubles; doubles++)
                set.add(random.nextDouble());
            // Add some references
            final int numberOfReferences =
random.nextInt(Math.min(random.nextInt(5) + 1, Math.max(objects.size(), 1)));
            for (int references = 0; references < numberOfReferences;
references++)
                if (objects.size() > 0) {
                    set.add(objects.get(random.nextInt(objects.size())));
                } else {
                    set.add(objects);
                }
            objects.add(set);
        }
        return objects;
    }

    public static void main(String[] args) {
        final Serializable object = buildStructure(10000);
        Kryo kryo = new Kryo();
        kryo.register(HashSet.class, new DeflateCompressor(new
FieldSerializer(kryo, HashSet.class)));
        kryo.register(ArrayList.class);
        ByteBuffer bb = ByteBuffer.allocate(10000000);
        long start = System.currentTimeMillis();
        kryo.writeObject(bb, object);
        bb.flip();
        System.out.println("Kryo size = " + bb.remaining());
        Object result = kryo.readObject(bb, ArrayList.class);
        long elapsedKryo = System.currentTimeMillis() - start;
        System.out.println("Original hashCode = " + object.hashCode() + ",
Kryo result hashCode = " + result.hashCode() + ", elapsed = " + elapsedKryo);
        result = null;
        try {
            start = System.currentTimeMillis();
            byte[] serialized = serialize(object);
            System.out.println("Java Size = " + serialized.length);
            result = deserialize(serialized);
            long elapsedJava = System.currentTimeMillis() - start;
            System.out.println("Original hashCode = " + object.hashCode() +
", Java result hashCode = " + result.hashCode() + ", elapsed = " +
elapsedJava);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Original issue reported on code.google.com by [email protected] on 11 May 2010 at 6:44

exception thrown when using the remote object

What steps will reproduce the problem?
1.install java 7
2.run java program

What is the expected output? What do you see instead?
not to throw a exception, exception thrown saying the proxy class isnt 
registered

What version of the Kryo are you using?
newest

Please provide any additional information below.
it worked before i installed the new java

Original issue reported on code.google.com by [email protected] on 19 Jul 2011 at 2:04

Collections/Map/Array references at not handled by the ReferenceFieldSerializer

What steps will reproduce the problem?
1.When 2 objects reference the same collection/map/array and you make a 
roundtrip (serialize/deserialize), you end up with 2 collections/map/array 
instead of the same ones in each object.

What is the expected output? What do you see instead?
Serializing the same collection should result in only one collection after 
deserialization. Right now I end up with 2 collections. I understand the the 
ReferenceFieldSerializer is not intended to handle this case, because 
Collections/Map/Array are handled by other serializers so I made some 
modifications to the code to be able to handle this case with a decorator. If 
you want to integrate it to kryo, feel free to, or maybe you have a better 
approch to propose.

What version of the Kryo are you using?
1.04

Please provide any additional information below.
Attached is a patch for the modifications and a jUnit test for the case.

Original issue reported on code.google.com by [email protected] on 2 Mar 2011 at 10:32

Attachments:

Incorrect (de)serialization of java.util.Date

What steps will reproduce the problem?
1. Make a new Kryo object and register java.util.Date class.
2. Make a new Date object and serialize it.
3. Deserialize the Date object.

What is the expected output? What do you see instead?
The original date object and the deserialized one should be identical.

What version of the Kryo are you using?
1.01

Quick google'ing on this problem reveals a related note: 
http://stackoverflow.com/questions/2725233/kryo-serialization-library-is-it-used
-in-production

The workaroud provided there is to override the Date serializer:
[code]
kryo.register(Date.class, 
  new SimpleSerializer<Date>() {
   @Override public void write (ByteBuffer b, Date d) { b.putLong(d.getTime()); }
   @Override public Date read (ByteBuffer b) { return new Date(b.getLong()); }
  });
[/code]

I attached a unit test to reproduce the problem. It also contains the 
workaround code.

Original issue reported on code.google.com by [email protected] on 3 Aug 2010 at 11:48

Attachments:

StringSerializer decode error

StringSerializer's get() reads too much data from the buffer.

put() counts byte[]'s length, but get() reads char[length],
As some char is more then 1 byte(eg. chinese), it causes an error.

The fixed get() looks like:
    static public String get (final ByteBuffer buffer) {
        int length = IntSerializer.get(buffer, true);
        Context context = Kryo.getContext();
        byte[] bytes = (byte[])context.get("byteArray");
        if (bytes == null || bytes.length < length) {
            bytes = new byte[length];
            context.put("byteArray", bytes);
        }
        buffer.get(bytes, 0, length);
        return new String(bytes, 0, length, charset);
    }

Original issue reported on code.google.com by [email protected] on 30 Oct 2009 at 11:53

BufferUnderflowException in CompatibleFieldSerializer

What steps will reproduce the problem?
Serializing large objects extends the Context.getByteArray() indefinitely ( and 
it seems it is not reset under any conditions ). On subsequent calls to 
serialize ( another or the same object ) the temp byte array is still very 
large and may exceed the length of available bytes in the buffer on buffer.get()


What is the expected output? What do you see instead?
BufferUnderflowException thrown at line 189 of CompatibleFieldSerializer


What version of the Kryo are you using?
1.03

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 22 Dec 2010 at 9:51

Circular field-types

Hello

I'm just investigating alternativs for java serialization. We are using
SpringHTTPInvoker to transmit objects. After it seems everything should run
now. I run into a Stackoverflow during serialisation. We have a quite
complex entity-structure where it is possible to navigate forth and back
through the object tree. When I look at the stacktrace I would say the
repeating fieldtypes are the problem.

java.lang.StackOverflowError
    at java.lang.reflect.AccessibleObject.<init>(AccessibleObject.java:137)
    at java.lang.reflect.Field.<init>(Field.java:104)
    at java.lang.reflect.Field.copy(Field.java:127)
    at java.lang.reflect.ReflectAccess.copyField(ReflectAccess.java:122)
    at sun.reflect.ReflectionFactory.copyField(ReflectionFactory.java:289)
    at java.lang.Class.copyFields(Class.java:2739)
    at java.lang.Class.getDeclaredFields(Class.java:1743)
    at
com.esotericsoftware.kryo.serialize.FieldSerializer.rebuildCachedFields(FieldSer
ializer.java:65)
    at
com.esotericsoftware.kryo.serialize.FieldSerializer.<init>(FieldSerializer.java:
52)
    at com.esotericsoftware.kryo.Kryo.getDefaultSerializer(Kryo.java:224)
    at com.esotericsoftware.kryo.Kryo.getRegisteredClass(Kryo.java:240)
    at
com.esotericsoftware.kryo.serialize.FieldSerializer.rebuildCachedFields(FieldSer
ializer.java:100)
    at
com.esotericsoftware.kryo.serialize.FieldSerializer.<init>(FieldSerializer.java:
52)
    at com.esotericsoftware.kryo.Kryo.getDefaultSerializer(Kryo.java:224)
    at com.esotericsoftware.kryo.Kryo.getRegisteredClass(Kryo.java:240)
    at
com.esotericsoftware.kryo.serialize.FieldSerializer.rebuildCachedFields(FieldSer
ializer.java:100)
    at
com.esotericsoftware.kryo.serialize.FieldSerializer.<init>(FieldSerializer.java:
52)
    at com.esotericsoftware.kryo.Kryo.getDefaultSerializer(Kryo.java:224)
    at com.esotericsoftware.kryo.Kryo.getRegisteredClass(Kryo.java:240)
    at
com.esotericsoftware.kryo.serialize.FieldSerializer.rebuildCachedFields(FieldSer
ializer.java:100)
    at
com.esotericsoftware.kryo.serialize.FieldSerializer.<init>(FieldSerializer.java:
52)
    at com.esotericsoftware.kryo.Kryo.getDefaultSerializer(Kryo.java:224)
    at com.esotericsoftware.kryo.Kryo.getRegisteredClass(Kryo.java:240)
<snip>

I'm wondering if kryo would have the same problem with repeated objects and
circular references.
Maybee an IdentiyHashMap would solve this during processing the fields.

Cheers
Marco

What version of the product are you using? On what operating system?
Windows Kryo 0.99

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 1 Mar 2010 at 8:08

The size of the serialized array which contains the same String refrence is larger than java built-in

What steps will reproduce the problem?
1.create a string array which contains the same String reference
2.serialize the array with kryo and java built-in
3.you will see the size of kryo is much more than java

What is the expected output? What do you see instead?
I think the same String should only be serialized once.
And the size of the array should be smaller than java built-in.

What version of the Kryo are you using?
1.04

Please provide any additional information below.
the code is here:
@Test
    public void testStringSer() throws IOException{
        char[] chars = new char[1500];
        Arrays.fill(chars, 'a');
        String str = new String(chars);
        testStringSer(str);

        String[] strArray = new String[]{str, str, str};
        testStringArraySer(strArray);
    }

    private void testStringSer(String str) throws IOException{
        Kryo kryo = new Kryo();
        kryo.setRegistrationOptional(true);
        ObjectBuffer ob = new ObjectBuffer(kryo, 5 * 1024);
        byte[] bytesKryo = ob.writeObjectData(str);
        System.out.println("kryo byte length of string:"+ bytesKryo.length);

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(str);
        byte[] bytesJava = bos.toByteArray();
        bos.close();
        oos.close();
        System.out.println("java byte length of string:"+bytesJava.length);
    }

    private void testStringArraySer(String[] strArray) throws IOException{
        Kryo kryo = new Kryo();
        kryo.setRegistrationOptional(true);
        ObjectBuffer ob = new ObjectBuffer(kryo, 5 * 1024);
        byte[] bytesKryo = ob.writeObjectData(strArray);
        System.out.println("kryo byte length of string array:"+ bytesKryo.length);

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(strArray);
        byte[] bytesJava = bos.toByteArray();
        bos.close();
        oos.close();
        System.out.println("java byte length of string array:"+bytesJava.length);
    }

and the result is:
kryo byte length of string:1502
java byte length of string:1507
kryo byte length of string array:4511
java byte length of string array:1557

Original issue reported on code.google.com by [email protected] on 20 Apr 2011 at 4:24

Forward and backward compatibility

Current Kryo object graph serializers (eg, FieldSerializer) use the Java
class definition as a schema. This reduces serialized size because the data
for an object's fields is written in a known order; there is no need to
write field identifiers. The drawback is that any change to the class
definition invalidates serialized bytes made with the old class definition.

Both scenarios should be supported. Some uses of Kryo have short-lived
serialized bytes (eg, IPC or a networked game) and gladly sacrifice
forward/backward compatibility for smaller serialized size. Other uses keep
serialized bytes around for a long time (eg, storing them on disk or in a
database) and it would be unacceptable to invalidate all existing data when
a class is modified.

To support forward/backward compatibility, during serialization, the first
time an object type is encountered the field names would be written. This
defines the order the field values will appear in the serialized bytes for
that type. If a field no longer exists, it is ignored. Fields not in the
serialized bytes are left unchanged.

It isn't terribly efficient to write the field name as Strings. Possibly an
annotation could be provided that would allow fields to be given an
ordinal, allowing the field to be referenced with just 1 byte rather than 1
byte per character in its name.

Original issue reported on code.google.com by [email protected] on 25 Mar 2010 at 1:11

Implement exception with details on unregistered class, or callback

Steps will reproduce the problem:
1. kryo.writeClassAndObject(buffer, object); // when object's class or some 
class from its graph is not registered 
2. you get IllegalArgumentException exception with textual description of 
class, like "Class is not registered: <Class name>" 

Instead, it would be better to throw an exception with explicit Class 
property in it, to make it possible to see which class was not registered. 
With the code like this:

throw new KryoUnregisteredException(type, "Class is not registered: "...)

This addition is needed to register classes dynamically in runtime, and 
retry the serialization until all classes are registered.

Alternative solution would be to use user-supplied callback code which 
performs registration instead of throwing an exception.

Original issue reported on code.google.com by [email protected] on 27 Feb 2010 at 7:06

Better error reporting for FieldSerializer

Right now, when there's an error during deserialization somewhere below 
FieldSerializer.readObjectData it's hard to tell what's the reason for the 
issue.

For debugging I deployed patched the FieldSerializer so that I was able to 
locate the issue.

The attached patch is a suggestion for an improvement.

Original issue reported on code.google.com by martin.grotzke on 26 May 2010 at 2:48

Attachments:

Provide maven pom.xml

In kryo-serializers I just wanted to reference the latest kryo from trunk 
without just referencing the projects 
in eclipse :-)

For this I created a very simple pom.xml (for maven2) that builds kryo, see the 
file attached.
As version I chose 1.1-SNAPSHOT as a wild guess. Stuff like scm info, license, 
mailing list etc. is left out...

When you run "$ mvn install" maven tells you that neither minlog nor reflectasm 
is available in public repos 
and that you need to install them. So just do
$ mvn install:install-file -DgroupId=com.esotericsoftware 
-DartifactId=reflectasm -Dversion=0.8 -
Dpackaging=jar -Dfile=lib/reflectasm-0.8.jar
and
$ mvn install:install-file -DgroupId=com.esotericsoftware -DartifactId=minlog 
-Dversion=1.2 -
Dpackaging=jar -Dfile=lib/minlog-1.2.jar
and afterwards again
$ mvn install

Then everything's fine.

It would be great to find this or s.th. similar in kryo. :)

Original issue reported on code.google.com by martin.grotzke on 5 Apr 2010 at 7:17

  • Merged into: #13

Attachments:

Maven repo

plz provide kryo as maven artifacts

Original issue reported on code.google.com by anightl on 25 Mar 2010 at 1:25

Provide possibility to set the RegisteredClass for a given type - putRegisteredClass(Class, RegisteredClass)

Hi Nate,

I'd like to have the possibility to set a given RegisteredClass for a certain 
type, e.g. via s.th. like
  void putRegisteredClass( Class type, RegisteredClass registeredClass )

My situation is the following: I have a serializer for cglib proxies that I 
register using a marker class:
  kryo.register( CGLibProxySerializer.CGLibProxyMarker.class, new CGLibProxySerializer( kryo ) );

When a cglib proxy class is written via Kryo.writeClass, this proxy class is 
not yet known as it's s.th. like
  MSM_de.javakaffee.kryoserializers.cglib.CGLibProxySerializerTest$MyServiceImpl$$EnhancerByCGLIB$$d0595dcf

For this class I want to register the previously registered 
CGLibProxySerializer, so that this one is used for the actual proxy class.

I know that I could override getRegisteredClass(Class) like this:
  public RegisteredClass getRegisteredClass( final Class type ) {
    if ( CGLibProxySerializer.canSerialize( type ) ) {
      return super.getRegisteredClass( CGLibProxySerializer.CGLibProxyMarker.class );
    }
    return super.getRegisteredClass( type );
  }

Unfortunately, CGLibProxySerializer.canSerialize( type ) is rather expensive 
and this would be called for each writeClass, so I'd prefer to just override 
handleUnregisteredClass(Class):
  protected void handleUnregisteredClass( final Class type ) {
    if ( CGLibProxySerializer.canSerialize( type ) ) {
      putRegisteredClass( type, getRegisteredClass( CGLibProxySerializer.CGLibProxyMarker.class ) );
    }
    else {
      super.handleUnregisteredClass( type );
    }
  }

The patch for putRegisteredClass(Class, RegisteredClass) is attached.

Can you include this or s.th. similar in kryo?

Thx && cheers,
Martin

Original issue reported on code.google.com by martin.grotzke on 25 Jun 2010 at 8:16

Attachments:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.