public interface AsciiSerializable extends java.io.Serializable, FieldAccessor
AsciiSerialable Objects must follow the following rules:
1. They must have a public no argument constructor
2. Multidimensional arrays are currently not supported
3. All member variables that are not to be AsciiSerialized need to be marked as transient
4. If the Object contains any private or protected fields then the class needs to have a
getFieldObject(Field) and setFieldObject(Field,Object) set of methods,
even if the parent class has them.
Examples of getFieldObject(Field) and setFieldObject(Field, Object)
If the Object extends an AsciiSerialiable Object then use the following 2 methods:
public Object getFieldObject(java.lang.reflect.Field fld)
{
try {
Object obj = fld.get(this);
return obj;
}
catch( IllegalAccessException e) {
return super.getFieldObject(fld);
}
}
public boolean setFieldObject(java.lang.reflect.Field fld, Object fobj)
{
try {
fld.set(this,fobj);
return true;
}
catch( IllegalAccessException e) {
return super.setFieldObject(fld, fobj);
}
catch( IllegalArgumentException e) {
return super.setFieldObject(fld, fobj);
}
}
If the Object is the base AsciiSerialiable Class then use the following 2 methods:
public Object getFieldObject(java.lang.reflect.Field fld)
{
try {
Object obj = fld.get(this);
return obj;
}
catch( IllegalAccessException e) {
return null;
}
}
public boolean setFieldObject(java.lang.reflect.Field fld, Object fobj)
{
try {
fld.set(this,fobj);
return true;
}
catch( IllegalAccessException e) {
return false;
}
catch( IllegalArgumentException e) {
return false;
}
}
Example of code to AsciiSerialize an Object
AsciiSerializer as = new AsciiSerializer(writer);
as.serializeObject(this);
writer.close();
Example of code to AsciiDeserialize an Object
AsciiDeserializer as = new AsciiDeserializer(reader);
as.deserializeObject(this);
reader.close();
getFieldObject, setFieldObject