package me.itszooti.geojson.gson;

import java.lang.reflect.Type;

import me.itszooti.geojson.GeoGeometry;
import me.itszooti.geojson.GeoPoint;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

public class GeoGeometrySerializer implements JsonSerializer<GeoGeometry> {

	@Override
	public JsonElement serialize(GeoGeometry geom, Type type, JsonSerializationContext context) {
		// always an object with type
		JsonObject obj = new JsonObject();
		obj.addProperty("type", geom.getClass().getSimpleName().substring(3));
		
		// check type
		if (geom instanceof GeoPoint) {
			GeoPoint point = (GeoPoint)geom;
			obj.add("coordinates", context.serialize(point.getPosition()));
		}
		
		return obj;
	}

}

@@ -100,16 +100,58 @@
 ometry;%0A
+import me.itszooti.geojson.GeoLineString;%0A
 import m
@@ -821,16 +821,186 @@
 on()));%0A
+%09%09%7D else if (geom instanceof GeoLineString) %7B%0A%09%09%09GeoLineString lineString = (GeoLineString)geom;%0A%09%09%09obj.add(%22coordinates%22, context.serialize(lineString.getPositions()));%0A
 %09%09%7D%0A%09%09%0A%09

Implement LineString encoding