Hmm, no answer yet. So I have to investigate myself :-(

Here's what I found out so far:

1) Simple classes with primitive instance variables are not a problem for MINA. Works just fine.
2) Classes with objects don't work.


To test 2), I did the following:

I created this Test-Class which will be serialized later:

----
package de.root1.shared;

import java.io.Serializable;
import java.math.BigInteger;

public class MyClass implements Serializable {

    private static final long serialVersionUID = 123L;

    private long i = 0;
    private BigInteger bigInt;
    private final String string;

    public MyClass(long i, String bigint, String string) {
        this.i = i;
        this.bigInt = new BigInteger(bigint);
        this.string = string;
    }

    public long getI() {
        return i;
    }

    @Override
    public String toString() {
return "MyClass{" + "i=" + i + ", bigInt=" + bigInt.longValue() + ", string=" + string + '}';
    }

}
----

... and executed the following code to serialize an object of this class once on Android 4.2.2 and once on JVM:

----
            Long l = 26495472873L;
            MyClass mc = new MyClass(l, "1234567890", "Hello World:" + l);
            IoBuffer ioBuffer = IoBuffer.allocate(1024 * 10);

            ioBuffer.putObject(mc);
            ioBuffer.flip();

            StringBuilder sb = new StringBuilder();
            while (ioBuffer.position() < ioBuffer.limit()) {
                sb.append(ioBuffer.get()).append("|");
            }
            System.out.println("buffer: " + sb.toString());
----

I expected that both platforms would create the same output. But it's different:

JVM 1.7u21 64bit
buffer: 0|0|0|-102|-84|-19|0|5|115|114|1|0|23|100|101|46|114|111|111|116|49|46|115|104|97|114|101|100|46|77|121|67|108|97|115|115|120|112|0|0|0|6|43|64|-44|-23|115|114|1|0|20|106|97|118|97|46|109|97|116|104|46|66|105|103|73|110|116|101|103|101|114|120|114|1|0|16|106|97|118|97|46|108|97|110|103|46|78|117|109|98|101|114|120|112|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-2|-1|-1|-1|-2|0|0|0|1|117|114|1|0|2|91|66|120|112|0|0|0|4|73|-106|2|-46|120|116|0|23|72|101|108|108|111|32|87|111|114|108|100|58|50|54|52|57|53|52|55|50|56|55|51|

ANDROID 4.2.2 on Android-SDK-Emulator
buffer: 0|0|0|-118|-84|-19|0|5|115|114|1|0|23|100|101|46|114|111|111|116|49|46|115|104|97|114|101|100|46|77|121|67|108|97|115|115|120|112|0|0|0|6|43|64|-44|-23|115|114|1|0|20|106|97|118|97|46|109|97|116|104|46|66|105|103|73|110|116|101|103|101|114|120|114|1|0|16|106|97|118|97|46|108|97|110|103|46|78|117|109|98|101|114|120|112|0|0|0|1|117|114|1|0|2|91|66|120|112|0|0|0|4|73|-106|2|-46|120|116|0|23|72|101|108|108|111|32|87|111|114|108|100|58|50|54|52|57|53|52|55|50|56|55|51|

A lot of bytes are equal, but after a lot of bytes, there's a point where the JVM uses the following additional bytes: "-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-1|-2|-1|-1|-1|-2|".

So the part before this substring, and the part after this substring is equal to the Android output...

On both systems, I don't get any exception.

Any ideas what goes wrong?

br,
Alex






Am 23.04.2013 11:47, schrieb Alexander Christian:
Hi there,

a few months ago, I asked this list if someone uses MINA for communication between Android (DalvikVM) + Java (Oracle JVM), especially with regard to built-in object serialization

This was the answer (forget to copy also the author's name ...):
----

Yes, MINA works on Android!

I have been using it to develop a publish/subscribe system that supports Android clients. I think you won't be able to use built-in serialization, though. Dalvik is not a standard JVM...

Other than that, I've had no issues.

My deployments include Android 2.3 and Android 4.1 using Nexus S smartphones and the latest version of MINA. In fact, I think they are a great combination...

----

Today I tested my application (which is a kind of RMI replacement, see http://dev.root1.de/projects/simon and makes heavy use of serialization via IoBuffers#getObject/putObject) with Android 4.2.2 (via Android SDK Emulator). Result: Serialization works... At least with simple classes like:

----
package de.root1.shared;

import java.io.Serializable;

public class MyClass implements Serializable {

    private long i = 0;

    public MyClass(long i) {
        this.i = i;
    }

    public long getI() {
        return i;
    }

    @Override
    public String toString() {
        return "MyClass{" + "i=" + i + "}@"+hashCode();
    }

}
----

For now, I did not test complex classes. But I assume that this will also work.

So: Great. Serialization works. But why? I read that it is not working? I found a lot of resources on the net talking about other ways of serialization and ways around this issue...

Is there someone on this list who can confirm that serialization between DalvikVM and JVM with help of MINAs IoBuffer#putObject/getObject is not an issue at all? My gurrent guess is, that serialization between both platforms became compatible with Android Version XYZ ... Would be good to know which version this was...

Any comments/ideas?

br,
Alex


Reply via email to