user376112
user376112

Reputation: 869

Common serializer for php and java Object

I'd like to serialize an object from java and to unserialize this object in PhP. I saw different classes in java that does this but they are not able to serialize not primitive object.

By the way, do you know where I can read the details of the language generated by the function 'serialize' of php?

Thank you very much

Bat

Upvotes: 0

Views: 734

Answers (2)

rjsang
rjsang

Reputation: 1757

What you need is to make the Java serialization produce a serialized form that PHP understands. This can be done by creating a method with the following signature:

private void writeObject(OutputStream out)

on the Java class. This can be used to customise the serialized form of the object. Check out this excerpt from the excellent book Effective Java by Joshua Bloch that explains how to do this (you'll need to subscribe or get a free trial to read the link, but I do recommend it)

http://my.safaribooksonline.com/book/programming/java/9780137150021/serialization/ch11lev1sec2

Unfortunately, not being a PHP developer, I can't comment too much on what the form should be. Hopefully, someone else here can help you with that.

Upvotes: 0

deceze
deceze

Reputation: 522322

When unserializing an object in PHP, PHP needs to have the class definition of that object. I doubt you'll get very far if the original class is a Java class.

I'd suggest you go for a language neutral data encapsulation format like JSON. This can be json_decoded into a stdClass object.

Upvotes: 1

Related Questions