My problem is like this. I have serialized binary Java objects stored in files. I need to reconstruct the objects in C++ and do further process.
I think I can deserialize the Java objects using Java, serialize again into acsii files, then load in C++ code. Also, I know it's possible to call Java function from C++ using JNI, but I don't know how to pass parameters, i.e., return the objects back to C++. But is there a better way?
Thanks!
If you feel brave enough, you could look at the Java serialization specification and write a C++ parser for Java serialized data.
The JNI route works, but you end up with Java objects, not C++ objects. So your C++ code will basically have to make lots of calls into the VM to manipulate that data (although you could do it just to fetch the object's field and copy them into a C++ object).
If writing a Java unmarshaler in C++ sounds like to much trouble, you could do what yourself suggested and write a Java program that writes data into a format that you can easily parse from C++. But now you're writing both a marshaler (in Java) and, if you don't have one, an unmarshaler (in C++), so maybe just parsing the Java serialized format would be easier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With