Class DateAsTimeSinceEpochTypeAdapter

  • All Implemented Interfaces:
    com.google.gson.JsonDeserializer<Date>, com.google.gson.JsonSerializer<Date>

    public class DateAsTimeSinceEpochTypeAdapter
    extends Object
    implements com.google.gson.JsonSerializer<Date>, com.google.gson.JsonDeserializer<Date>
    Converts Date instances in JSON objects to or from timestamps since the epoch.
    Author:
    Jon Chambers
    • Constructor Detail

      • DateAsTimeSinceEpochTypeAdapter

        public DateAsTimeSinceEpochTypeAdapter​(TimeUnit timeUnit)
        Constructs a new date/timestamp type adapter that uses the given time unit to measure time since the epoch.
        Parameters:
        timeUnit - the time unit in which to express timestamps
    • Method Detail

      • deserialize

        public Date deserialize​(com.google.gson.JsonElement json,
                                Type typeOfT,
                                com.google.gson.JsonDeserializationContext context)
                         throws com.google.gson.JsonParseException
        Specified by:
        deserialize in interface com.google.gson.JsonDeserializer<Date>
        Throws:
        com.google.gson.JsonParseException
      • serialize

        public com.google.gson.JsonElement serialize​(Date src,
                                                     Type typeOfSrc,
                                                     com.google.gson.JsonSerializationContext context)
        Specified by:
        serialize in interface com.google.gson.JsonSerializer<Date>