Serializable Features: How to Transfer Feature Objects
The following classes provide Serializable wrappers around Feature and type objects. There are some comments in Geotools data classes like "// TODO consider serialization". But just marking Feature Serializable would require a fair amount of work and might cause some problems. A Feature references a FeatureType, which references many AttributeTypes, which contain things like GeometryFactories. And do we really want to send a GeometryFactory object when we just want to transfer a Feature? The following classes crystalize what's important about each of these objects to make serialization nearly pain-free. (Note: GisException is a subclass of RuntimeException which allows the to ignore the particulars of failure. You can write one yourself or you can handle the various catch blocks however you like.)
Suppose you have two programs which communicate via serialization (RMI, for instance). To transfer data from one to the other, all you have to do (assuming sendSerializedObject() serializes and sends to a receiveSerializedObject() method which calls receiveFeatures and assuming processFeatureCollection does something interesting) is:
You can also send individual Features, FeatureTypes, and AttributeTypes. So one program could ask another for a FeatureType independently of any features.
Some brief tests suggest that this methodology is up to 10 times faster than generating GML, saving it, and parsing it. (Which is admittedly slower than WFS, but can be done without a web container.)