Jeff
Jeff

Reputation: 1

Reading a Java Object in PHP from a file created with ObjectOutputStream

I'm trying to read a file that was created in a Java-based game using ObjectOutputStream in PHP. The data is a serialized object written in a binary format.

I've been using fopen and fread to get the binary data, but I have absolutely no idea what to do with it.

Upvotes: 0

Views: 1732

Answers (3)

mario
mario

Reputation: 145512

It doesn't seem easy to reimplement http://download.oracle.com/javase/6/docs/platform/serialization/spec/protocol.html

Upvotes: 1

BalusC
BalusC

Reputation: 1109402

PHP doesn't understand Java. Both do however understand a common format like JSON, XML, CSV, etc. I'd suggest to change the format to either of them and use that as data transfer format instead.

In case of JSON, you can in Java use Google Gson to convert (encode) fullworthy javabeans into JSON flavor and in PHP you can use json_decode() to convert (decode) it into an associative PHP array.

Upvotes: 4

Jack
Jack

Reputation: 133619

You can't do it so easily (unless an existing framework is available). This because the binary format used by Java serialization is highly specialized to the JVM, think that there's not guaranteed compatibility even between different JVM versions.

You should use a different approach, for example using XML, YAML or JSON..

Upvotes: 0

Related Questions