Unserialize in Java a serialized php object

前端 未结 15 997
闹比i
闹比i 2020-11-29 11:31

Does anyone know if it is possible, actually if it has been done, to serialize an object in php and unserialize it in Java (java-php communication). Maybe an adapter will be

相关标签:
15条回答
  • 2020-11-29 12:04

    Serializing an object in PHP will dump the object properties. The resulting string isn't terribly complicated.

    echo serialize(
        array(1, null, "mystring", array("key"=>"value"))
    );
    

    Results in:

    a:4:{i:0;i:1;i:1;N;i:2;s:8:"mystring";i:3;a:1:{s:3:"key";s:5:"value";}}
    

    The string identifies datatypes, array lengths, array indexes and values, string lengths... Wouldn't take too much effort to reverse-engineer it and come up with your own parser, I think.

    0 讨论(0)
  • 2020-11-29 12:04

    Try xstream (converts Java objects into readable XML) to serialize and then write your own PHP code to deserialize.

    0 讨论(0)
  • 2020-11-29 12:05

    Use Web Services (REST, RPC, SOAP) or any other solution storing plain text that will allow you to read/rebuild the data from Java.

    0 讨论(0)
提交回复
热议问题