开发者

Common serializer for php and java Object

开发者 https://www.devze.com 2023-02-01 02:04 出处:网络
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开发者_如何学Go not able to serialize not primitive 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开发者_如何学Go 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


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.


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.

0

精彩评论

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