• This repository has been archived on 26/Jul/2020
  • Stars
    star
    102
  • Rank 334,571 (Top 7 %)
  • Language
    Java
  • License
    MIT License
  • Created almost 13 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Library for serializing Java objects into the PHP serializing format and unserializing data from this format back into Java objects.

DEPRECATION NOTICE

This project is no longer maintained since years as I'm no longer active in Java and PHP development. Feel free to take over the project if you think the world still needs this.

Pherialize

Description

Pherialize is a small library allowing serializing Java objects into the PHP serializing format and unserializing data from this format back into Java objects.

So with Pherialize you can serialize PHP objects and unserialize them into Java objects and vice versa. With a similiar implementation in JavaScript you can also use Pherialize to transfer data between Java and JavaScript if you like.

Up to now Pherialize can serialize the following Java data types:

  • null
  • Boolean
  • String
  • Char
  • Byte
  • Integer
  • Short
  • Long
  • Float
  • Double
  • List
  • Map
  • Arrays
  • Serializable (Through Reflection API)
  • Mixed
  • Enums (Value used as string)

The Unserializer supports the following PHP data types:

  • null
  • boolean
  • string
  • int
  • double
  • array

References are supported, too. This allows you to serialize and unserialize even complex types with circular references in it.

License

Copyright (c) 2006 Klaus Reimer [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Download

The JAR can be downloaded from my Maven Repository or if you are using Maven you can simply add it as a dependency:

<repositories>
  <repository>
    <id>ailis-releases</id>
    <name>Ailis Maven Releases</name>
    <url>http://nexus.ailis.de/content/groups/public/</url>
  </repository>
</repositories>

<dependencies>
  <dependency>   
    <groupId>de.ailis.pherialize</groupId>
    <artifactId>pherialize</artifactId>
    <version>1.2.1</version>
  </dependency>
</dependencies>

Usage

How to serialize data

For serializing a Java object into a PHP serialization format string you just use the static method Pherialize.serialize(). Just pass the object you want to serialize to this method and you get a string in return which you can then unserialize in PHP.

Example:

List list;

list = new ArrayList();
list.add("A string");
list.add(Integer.valueOf(12345));
list.add(Boolean.TRUE);
System.out.println(Pherialize.serialize(list));

The result is printed to stdout and looks like this:

a:3:{i:0;s:8:"A string";i:1;i:12345;i:2;b:1;}

Now you can use this string in PHP to unserialize it back into a PHP array:

$data = unserialize('a:3:{i:0;s:8:"A string";i:1;i:12345;i:2;b:1;}');
var_dump($data);

Result is a PHP array with exactly the data and types you have added to the array with Java:

array(3) {
  [0]=>
  string(8) "A string"
  [1]=>
  int(12345)
  [2]=>
  bool(true)
}

How to unserialize data

Let's assume you have serialized the PHP array from the previous example and you have stored this serialized string in the variable data. For unserializing and printing the value you just have to use the Pherialize.unserialize() method.

Example:

MixedArray list;

list = Pherialize.unserialize(data).toArray();
System.out.println("Item 1: " + list.getString(0));
System.out.println("Item 2: " + list.getInteger(1));
System.out.println("Item 3: " + list.getBoolean(2));

The correct result printed to stdout is this:

Item 1: A string
Item 2: 12345
Item 3: true

Types

Because the data types in PHP are different to the types in Java conversion is not always possible without switching to a different data type. If for example you serialize a Java Byte then you will get a PHP int because PHP does only knows the number types int and double. So when you unserialize this int back into Java then you will end up with an Integer and not with a Byte. The same problem comes up with Long objects. Pherialize serializes a Long into a int if it fits an Integer. Otherwise it's serialized into a double

To make life easier while unserializing PHP data into Java all PHP data types are wrapped by an object of type Mixed. From this object you can convert the data easily in whatever you need (as long as the conversion makes sense).

Here is a complete list of the conversions performed when serializing Java data types and unserializing them in PHP:

Java class PHP type
null null
Boolean boolean
Character string
Byte int
Short int
Integer int
Long int or double (Depending on how large the value is)
Float double
Double double
String string
Collection array
Map array
Serializable object
Enum Value used as a string
Mixed Depends on the raw type in the Mixed wrapper

And here is a list of performed conversion when you unserialize PHP data in Java. But note that you will never get in touch with these conversions because it's completely hidden by the .

PHP type Java class
null null
boolean Boolean
int Integer
double Double
string String
array Map

More Repositories

1

console-shim

Browser console compatibility shim for legacy JavaScript engines
JavaScript
86
star
2

xadrian

A factory complex calculator tool for X³: Terran Conflict and X³: Albion Prelude.
Java
26
star
3

jest-environment-node-single-context

Jest environment for Node with single context
TypeScript
23
star
4

jest-electron-runner

Custom test runner for Jest that allows tests to be run in Electron environment
TypeScript
20
star
5

canonn-decryptor

Tool to decrypt the mysteries of the Elite Dangerous universe
TypeScript
10
star
6

wlandsuite

Software for reading and writing data files of the famous game Wasteland.
Java
5
star
7

xgalaga-js

JavaScript port of the famous arcade game XGalaga from Joe Rumsey.
JavaScript
5
star
8

svtools

Some useful utilities to maintain supervised services and to handle multilog log files.
Shell
5
star
9

ed-journal

Typescript library to read/watch the player journal of Frontier's game Elite Dangerous
TypeScript
5
star
10

twodee

A small, fast and simple 2D scene graph vector engine for JavaScript based on the HTML 5 canvas technology.
JavaScript
5
star
11

text-encoding

Text Encoder and Decoder
TypeScript
4
star
12

scilter

A library with various different scaling algorithms like scale2x, scale3x, hq2x, hq3x and hq4x.
Java
4
star
13

jollada

Collada DOM API for Java.
Java
3
star
14

eddb

"Parses exported data from the Elite Dangerous Database (EDDB)
TypeScript
3
star
15

wastelib

A JavaScript library (Written in TypeScript) for reading the game assets of Wasteland.
TypeScript
2
star
16

tiled

A set of TypeScript interfaces, types and enums, API documentation, JSON file typings, JSON schema and helper functions to work with JSON files created by the Tiled map editor
TypeScript
2
star
17

phoolkit

A PHP toolkit
PHP
2
star
18

wlsuite

A shared library and a suite of programs for converting wasteland files into standard files and vice versa.
C
2
star
19

oneinstance

A Java library which can be used to prevent the launch of multiple instances of an application. The first instance is informed about the launch of a second one, can decide if the second instance is allowed to start and also gets the working directory and the command-line arguments of the second instance.
Java
2
star
20

destroids

Asteroids-like game written in JavaScript
JavaScript
1
star
21

libwasteland

A shared C++ library to read and write the files of the game Wasteland.
C++
1
star
22

modex

DOS graphics library using Mode-X
Assembly
1
star
23

wludata

Command-line tool to unpack the compressed files of the role playing game Wasteland into a format which can be read by the special Wasteland EXE file patched by the Wasteland Wikispaces project.
C
1
star