I have a BigInteger
serialized to a file by a Java program using the writeObject
method from ObjectOutputStream
.
Can I deserialize it in C#? I tried using the java.math
and java.io
classes of vjslib
, but I get an exception:
InvalidClassExce开发者_C百科ption the class does not match the class of the persisted object for cl = java.lang.Number : __SUID = -8742448824652078965, getSUID(cl) = 3166984097235214156
Any ideas?
Do you have control over the serialization step from Java?
If so, I would suggest serializing a byte array, either as binary, or base64, and reading the byte array from the serialized structure.
Then you can pass the byte array to the System.Numerics.BigInteger
constructor.
If you don't mind ugly hacks: I'd say the easiest (albeit not most efficient) way would be to just write it out as an ASCII String on the Java side, and parse that string on the C# side, instead of using binary de/serialization.
I suggest you don't use serialization for this, since the two versions of BigInteger
are not compatible - they have different version ids.
You should write the object out in some other way, probably using the byte array from BigInteger.toByteArray
Reading this this question about serialization might also be insightful for you
精彩评论