package me.pagar.util;

import com.google.common.base.Strings;
import com.google.gson.*;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;

import java.lang.reflect.Type;

public class DateTimeAdapter  implements JsonDeserializer<DateTime>, JsonSerializer<DateTime> {

    private final DateTimeFormatter formatter;

    public DateTimeAdapter() {
        this.formatter = ISODateTimeFormat
                .dateOptionalTimeParser()
                .withZoneUTC();
    }

    @Override
    public DateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        final String dateTime = json.getAsString();
        try {
            return Strings.isNullOrEmpty(dateTime) ? null : formatter.parseDateTime(dateTime);
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public JsonElement serialize(DateTime src, Type typeOfSrc, JsonSerializationContext context) {
        return src == null ? null : new JsonPrimitive(formatter.print(src));
    }

}

@@ -113,16 +113,60 @@
 teTime;%0A
+import org.joda.time.format.DateTimeFormat;%0A
 import o
@@ -485,19 +485,16 @@
 atter = 
-ISO
 DateTime
@@ -503,80 +503,44 @@
 rmat
-%0A                .dateOptionalTimeParser()%0A                .withZoneUTC(
+.forPattern(%22yyyy-MM-dd'T'HH:mm:ssZ%22
 );%0A 

fix date serialization