Fork me on GitHub

Tutorial 14

E14 Using a custom type conversion to modify KML coordinates

This tutorial demonstrates the usage of a custom made type converter. We implement a new Java List "CoordinateList" which will handle our user defined type Coordinate. So far this is not related to data projection, it's just the scenario build up to show how easy user defined typed may be integrated. The actual configuration of the projector is basically just one line of code.


public interface KML {
    public CoordinateList getCoordinates();
    public KML setCoordinates(CoordinateList coordinates);

Example Code

public class TestCustomTypeConversion {
     * This Conversion defines how String data is converted to our target type and
     * what default is to be applied when no data is available.
    private final class CoordinateListConversion extends DefaultTypeConverter.Conversion<CoordinateList> {
        private CoordinateListConversion() {
            super(new CoordinateList(""));
        public CoordinateList convert(final String data) {
            return new CoordinateList(data);
    public void testApplyOffsetToCoordinates() throws IOException {
        XBProjector projector = new XBProjector(new DefaultXMLFactoriesConfig().setNamespacePhilosophy(NamespacePhilosophy.AGNOSTIC));
        DefaultTypeConverter converter = new DefaultTypeConverter(Locale.getDefault(),TimeZone.getDefault()).setConversionForType(CoordinateList.class, new CoordinateListConversion());
        KML kml =;
        // Extract the list of coordinates
        CoordinateList coordinates = kml.getCoordinates();
        // Apply some offset
        for (Coordinate a:coordinates) {
        // Set the list again