Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deserialize in PHP an object serialized in Java

Is there any way to deserialize in PHP an object serialized in Java? IE If I have a Java class that implements Serialization and I use an ObjectOutputStream to write the object, and convert the result to a string, is there a way in PHP to take that string and create a similar object representation from it?

What does the Java Serialized data look like?

Response:

���sr�com.site.entity.SessionV3Data���������xpsr�java.util.HashMap���`��F�

loadFactorI� thresholdxp?@�����w������t� sessionIdt�0NmViMzUxYWItZDRmZC00MWY4LWFlMmUtZjg2YmZjZGUxNjg5xx

:)

like image 570
stevebot Avatar asked Oct 16 '25 12:10

stevebot


1 Answers

I would heavily recommend you don't do this. Java serialization is meant for a Java instance to both save and load the data (for either transmission to another Java application or persistence between invocations of the same application). It was not at all meant to be a cross-platform protocol.

I would advise you to make an API adapter layer between the two. Output the contents of your Java object to a format you can work with in PHP, be it XML, YAML, or even a binary format (where you could use DataOutputStream).

like image 140
Mark Peters Avatar answered Oct 18 '25 10:10

Mark Peters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!