package mn.devfest.api.adapter;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

import org.joda.time.DateTime;

import java.lang.reflect.Type;

/**
 * Adapts API dates to JodaTime DateTimes
 *
 * @author bherbst
 */
public class DateTimeTypeAdapter implements JsonDeserializer<DateTime> {
    @Override
    public DateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        return new DateTime(json.getAsString());
    }
}
@@ -196,16 +196,142 @@
 ception;
+%0Aimport com.google.gson.JsonPrimitive;%0Aimport com.google.gson.JsonSerializationContext;%0Aimport com.google.gson.JsonSerializer;
 %0A%0Aimport
@@ -530,16 +530,42 @@
 ateTime%3E
+, JsonSerializer%3CDateTime%3E
  %7B%0A    @
@@ -701,16 +701,16 @@
 ption %7B%0A
-
         
@@ -755,10 +755,239 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public JsonElement serialize(DateTime src, Type typeOfSrc, JsonSerializationContext context) %7B%0A        String jsonString = src == null ? %22%22 : src.toString();%0A        return new JsonPrimitive(jsonString);%0A    %7D
 %0A%7D

Add serialization to the date time adapter