Reading files / data structures from other platforms into Elixir/Erlang

And if it’s not JSON because of space restrictions, BERT or something similar could be used, it supports compression out of the box and is not restricted to printable characters.

I’m pretty sure there is a Java implementation out there…

You can even make this converter a port, or use jerlang or what was its name to call Java code directly…

1 Like

but not really so in my case… they have a system in place, it generates these zipped encrypted files.

The option i have is to read the files, decrypt, unzip, the read the content.

https://www.javaworld.com/article/2072752/the-java-serialization-algorithm-revealed.html is a great starting point … if only i can read back the file , like @tcoopman has been able to do.

I think there is still misunderstanding.

Yes – let the old system work the way it does. Nobody is arguing that.

No – do not use Erlang/Elixir to read serialized Java HashMap objects.

Yes – do write a Java tool that reads the serialized HashMap objects.

Yes – make that tool write the read HashMaps to JSON.

1 Like

And I never told you to change that. I have understood that you can not change the legacy system.

What we are suggesting is that you write a “third” program in Java, that does the conversion, depending on the type of the value in the map, either write out JSON or XML or BERT (aka Erlang External Term Format).

You have already Java code that shows you how to load the dump. Therefore loading and converting from there is probably the easiest thing to do.

Trying to load the unknown encoding in elixir/erlang code will be a lot of pain. We are just suggesting the easier ways. The BEAM is good in letting other programs work. Use it!

3 Likes

I wouldn’t classify serialized Java objects as a “common data structure”. You’d encounter similar problems trying to use Elixir to read data stored from Ruby’s Marshal, Python’s pickle or PHP’s serialize, all of which are intended for language-specific structure-preserving data storage.

Compare those to Erlang’s external term format, which is extensively documented specifically for interoperating with non-Erlang code.

+1 to writing an adapter program in Java, to let Java handle decoding its own data structures.

1 Like

Let’s see if actual code and working tool will help. I made a quick repo:

Compile and run instructions are in the README file.

After compilation I ran this:

java -cp gson-2.8.5.jar:. MapToJson ~/Downloads/sample1.zip

And voila, minified JSON on the standard output.

4 Likes