All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ardoq.adapter.Iso8601Adapter Maven / Gradle / Ivy

There is a newer version: 1.26
Show newest version
package com.ardoq.adapter;

import com.google.gson.*;

import javax.xml.bind.DatatypeConverter;
import java.lang.reflect.Type;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Iso8601Adapter implements JsonDeserializer, JsonSerializer {

    public Date deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
        Calendar calendar = DatatypeConverter.parseDateTime(jsonElement.getAsString());
        return calendar.getTime();
    }

    public JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) {
        GregorianCalendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.setTime(date);
        String s = DatatypeConverter.printDateTime(gregorianCalendar);
        return new JsonPrimitive(s);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy