public class PhpSerializer extends FilterWriter
Writer that is able to write out a Java object so PHP's
unserialize() function is able to read the result into a PHP variable.
The converter tries to find appropriate data types for conversion. The basic data types are as well supported as arrays, collections and maps.
Do not serialize more than one object, since more is not supported by PHP. If you need to pass several objects, pack them into an array and then serialize that array.
Note that Java Objects are not serialized in a manner that could be fully restored on
PHP side. Try to avoid sending pure Java Objects since the result is unpredictable (in
best case, it's just the toString() result that is being serialized).
Recursive references to the same object (i.e. an array with an element referring to that array) are not supported yet and will lead to a stack overflow.
out| Constructor and Description |
|---|
PhpSerializer(Writer w)
Creates a new PhpSerializer.
|
| Modifier and Type | Method and Description |
|---|---|
void |
serialize(boolean b)
Writes a boolean.
|
void |
serialize(char c)
Writes a char
|
void |
serialize(char[] c)
Writes a char array
|
void |
serialize(char[] c,
int offset,
int count)
Writes a section of a char array
|
void |
serialize(Collection<?> c)
Serializes a
Collection. |
void |
serialize(double d)
Writes a double.
|
void |
serialize(float f)
Writes a float.
|
void |
serialize(int i)
Writes an integer.
|
void |
serialize(long i)
Writes a long.
|
void |
serialize(Map<?,?> m)
Serializes a
Map. |
void |
serialize(Number n)
Serializes a
Number. |
void |
serialize(Object o)
Serializes an
Object. |
void |
serialize(Object[] a)
Serializes an array.
|
void |
serialize(String s)
Serializes a
String |
void |
serializeNull()
Writes a mere null pointer.
|
public PhpSerializer(Writer w)
w - Writer to write the output to.public void serialize(int i) throws IOException
i - Integer value to writeIOExceptionpublic void serialize(long i) throws IOException
i - Long value to writeIOExceptionpublic void serialize(boolean b) throws IOException
b - Boolean value to writeIOExceptionpublic void serialize(double d) throws IOException
d - Double value to writeIOExceptionpublic void serialize(float f) throws IOException
f - Float value to writeIOExceptionpublic void serialize(char c) throws IOException
c - Char value to writeIOExceptionpublic void serialize(char[] c) throws IOException
c - Array of chars to writeIOExceptionpublic void serialize(char[] c, int offset, int count) throws IOException
c - Array of chars to writeoffset - First index to writecount - Number of chars to writeIOExceptionpublic void serialize(String s) throws IOException
Strings - String to write, may be nullIOExceptionpublic void serialize(Number n) throws IOException
Number. BigDecimal and BigInteger is
supported, at least on the Java side. PHP might behave erratic when passing in very
large numbers.n - Number to write, may be nullIOExceptionpublic void serialize(Object[] a) throws IOException
Note that circular references cannot currently be serialized (e.g. the array itself must not be an element of that array) and will lead to a stack overflow.
a - Array to write, may be nullIOExceptionpublic void serialize(Collection<?> c) throws IOException
Collection. The collection's iterator is used to serialize
each entry of the Collection. On PHP side, an index array is created, with
the index counting from 0.
The Collection may contain null values and also nested arrays,
collections or maps.
Note that the Collection must not contain circular references.
c - Collection to write, may be nullIOExceptionpublic void serialize(Map<?,?> m) throws IOException
Map. The map's key iterator is used to serialize each entry of
the Map. On PHP side, an associative array is created, with the key being the map's
key, and the value being the map's appropriate value.
The Map may contain no more than one null key. Due to PHP
limitations, the key is always resolved using toString() unless it is a
Number object. This means that it is not possible to use collections, maps
or arrays as map keys.
The map's values may contain null and also nested arrays, collections or
maps.
Note that the map must not contain circular references.
m - Map to write, may be nullIOExceptionpublic void serialize(Object o) throws IOException
Object. If the object is found to be an instance of
String, Character, Boolean, Number,
Collection or Map, or if the object is an array, the appropriate
serialize() method is used. In all other cases, the object's
toString() result is serialized as a string.
Note that in future versions, Serializable objects may be serialized into PHP objects. For now, try to avoid to pass Serializable objects unless they are one of the basic types.
o - Object to write, may be nullIOExceptionpublic void serializeNull() throws IOException
IOExceptionCopyright © 2004–2016. All rights reserved.