开发者

How to unserialize user defined Java objects in Matlab that were serialized in java?

开发者 https://www.devze.com 2023-03-01 11:29 出处:网络
I have a simulator in Java serializing a custom Result object. I would like to unserialize these objects in Matlab for further statistical analysis.

I have a simulator in Java serializing a custom Result object. I would like to unserialize these objects in Matlab for further statistical analysis.

Is this possible?

The data in the Result object is heterogeneous. It contains another user defined class Parameters, linked lists of integers and doubles.

I edited the classpath.txt file to the root of my java package and imported both Result and Parameters with succes.

However, if I try to unser开发者_JS百科ialize an object with load('filename'); I get the following error

>> load('Type3aa_simpleToCreate_no_com.2011-04-28
 00.05.29.experiment.data') ??? Error using ==> load Number of columns on
 line 1 of ASCII file
 C:\Thesis\code\Thesis
 v0.7\Results\Type3aa_simpleToCreate_no_com.2011-04-28
 00.05.29.experiment.data must be the same as previous lines.


I'm not that familiar with mixing Matlab and Java, but decoding something that was encoded using Java serialization in something else than Java code seems like it would be difficult. Serialization mixes a lot of annotations that have to do with a specific compile of the Java code into the data.

I think you are better off writing the data in some text-like format if you want to read it into Matlab.

By the way, serialization has a number of problems that makes it rarely used, even just inside Java. The dependency on particular versions of class files is one thing, and another is that it is notoriously slow. I would personally not use it for anything, but prefer to invent my own encoding format, whether it be text/xml or some compact binary format.

Update: my opinions and experiences with the slowness of serialization are based on applications with very low tolerance for overhead, and may not be relevant for everyone.

0

精彩评论

暂无评论...
验证码 换一张
取 消