Question

I am working on a Lego Mindstorm NXT robot, which do not support Java reflection.

For some reason (the parallel creation of a simulator and an actual mindstorm) we want to use Serialization to exchange Java objects.

The problem is that serialization uses reflection, which the JVM on the mindstorm does not support.

Any ideas?

I found this page on Zwong.de, but the source code has been removed.

No correct solution

OTHER TIPS

Make your classes implement Externalizable, then ObjectOuputStream.writeObject() / readObject() will invoke writeExternal(ObjectOutput out) / readExternal(ObjectInput) on your objects directy, without using reflection

I believe Kryo supports reflection-less instantiation of serializable objects. A quick look on their home page seems to confirm it:

When ReflectASM or reflection cannot be used, Kryo can be configured to use an InstantiatorStrategy to handle creating instances of a class. Objenesis provides StdInstantiatorStrategy which uses JVM specific APIs to create an instance of a class without calling any constructor at all. This works on many JVMs.

It sounds from that like you'll need to create your own InstantiatorStrategy, since I'm not sure the standard one will have support for the NXT JVM - worth a try though! I haven't tried this myself, but it sounds like it should be possible in theory.

I found two possible leads. Hopefully these are of some help to you.

1) Doing Java serialization without reflection

2) xml serialization generator for java without using reflection

Serialization and deserialization is simply a way of writing and reading an object. You can always write your own methods that write and read all object data to/from a string/file/stream.

Moreover, custom serialization methods, especially these using binary data, are often less time, memory and processing power consuming than these provided by, ie., Serializable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top