com.ardoq.adapter.Iso8601Adapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-api-client Show documentation
Show all versions of java-api-client Show documentation
Java client to Ardoq public API
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