PL provides a free and open source implementation to demonstrate the usage of its format and types. The implementation is in the Java programming language. Source and binary download available.
The implementation can be used at 3 levels:
import alt.dev.pl.PLReader;
new PLReader( anInputStream ).readObject();
import alt.dev.pl.PLWriter;
new PLWriter( anOutputStream ).writeObject( anObject );
import alt.dev.pl.PL;
PL someProperties = new PL();
someProperties.load( anInputStream );
someProperties.store( anOutputStream );
import alt.dev.pl.PLObjectOutput;
PLObjectOutput.toString( anObject );
// Alternatively
new PLObjectOutput( anOutputStream ).writeObject( anObject );
deserializing an object back from PL
import alt.dev.pl.PLObjectInput;
PLObjectInput.valueOf( aString );
// Alternatively
new PLObjectInput( anInputStream ).readObject();
To overwrite the default serialization mechanism, you can register your own PLObjectInputReader and PLObjectOutputWriter.
PLObjectOutputWriter.registerWriter( aWriter );
PLObjectInputReader.registerReader( aReader );
Here is an example of a custom java.lang.StringBuffer reader and writer.
The Java implementation provides several custom types tailored for object serialization.
A x-bigdecimal is enclosed in double quotation marks and prefixed with the literal x-bigdecimal:. For example:
"x-bigdecimal:8.539734222673565966488240519"
Valid x-bigdecimal values are the one returned by java.math.BigDecimal.
A x-biginteger is enclosed in double quotation marks and prefixed with the literal x-biginteger:. For example:
"x-biginteger:88004293940654845815221765739"
Valid x-biginteger values are the one returned by java.math.BigInteger.
A x-class is enclosed in double quotation marks and prefixed with the literal x-class:. For example:
"x-class:java.lang.Runnable"
Valid x-class values are language specific. In Java, they reflect the value returned by java.lang.Class.
A x-field is a Map structure. For example:
{
":" = "x-field";
"name" = "serialVersionUID";
"class" = "x-class:java.util.HashMap";
"type" = "x-class:long";
}
Valid x-field values are language specific. In Java, they reflect the information provided by java.lang.reflect.Field.
A x-method is a Map structure. For example:
{
":" = "x-method";
"name" = "put";
"class" = "x-class:java.util.HashMap";
"types" =
(
"x-class:java.lang.Object",
"x-class:java.lang.Object"
);
"return" = "x-class:java.lang.Object";
}
Valid x-method values are language specific. In Java, they reflect the information provided by java.lang.reflect.Method and java.lang.reflect.Constructor.
A x-proxy is a Map structure. For example:
{
":" = "x-proxy";
"handler" =
{
":" = "x-object";
"class" = "x-class:PLTestTool";
"values" = "";
};
"interfaces" =
(
"x-class:java.lang.Comparable",
"x-class:java.util.Iterator",
"x-class:java.lang.Runnable"
);
}
Valid x-proxy values are language specific. In Java, they reflect the information provided by java.lang.reflect.Proxy.
A x-object is a Map structure. For example:
{
":" = "x-object";
"class" = "x-class:java.util.BitSet";
"values" =
{
"bits" =
(
"long:0"
);
};
}
Valid x-object values are language specific. In Java, they reflect the information provided by java.lang.reflect.
A x-java-serialized-object is a Map structure. For example:
{
":" = "x-java-serialized-object";
"class" = "x-class:java.util.Date";
"value" = <ACED00057>;
}
Valid x-java-serialized-object values are specific to java.io.ObjectOutputStream.
* * *