GeoTools : SerializationConsiderations

Expanding upon the Feature serializers mentioned in SerializableFeatures, there may be a need to serialize a Style, say to send it over RMI. One way (probably a bit slow) is simply to encode it in XML and place it in a String.

Example

StyleSerialization.java
static Style xmlToStyle(String styleString)
{
	if (styleString != null && styleString.trim().length() > 1)
	{
		ByteArrayInputStream input = new ByteArrayInputStream(styleString.getBytes());
		SLDParser styleReader = new SLDParser(StyleFactory.createStyleFactory(), input);
		Style style = styleReader.readXML()[0];
		return style;
	}
	return null;
}

static String styleToXml(Style style)
{
	SLDTransformer st = new SLDTransformer();
	return st.transform(style);
}