Sha256: 7e7cf4e5daf856e3008d7bef9ba1fbfd565626db4cee461bb6bdd6b15282b500

Contents?: true

Size: 1.65 KB

Versions: 51

Compression:

Stored size: 1.65 KB

Contents

package org.embulk.spi.time;

import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.deser.std.FromStringDeserializer;
import com.fasterxml.jackson.module.guice.ObjectMapperModule;

public class TimestampSerDe
{
    public static void configure(ObjectMapperModule mapper)
    {
        SimpleModule module = new SimpleModule();
        module.addSerializer(Timestamp.class, new DateTimeZoneSerializer());
        module.addDeserializer(Timestamp.class, new DateTimeZoneDeserializer());
        mapper.registerModule(module);
    }

    public static class DateTimeZoneSerializer
            extends JsonSerializer<Timestamp>
    {
        @Override
        public void serialize(Timestamp value, JsonGenerator jgen, SerializerProvider provider)
                throws IOException
        {
            jgen.writeString(value.toString());
        }
    }

    public static class DateTimeZoneDeserializer
            extends FromStringDeserializer<Timestamp>
    {
        public DateTimeZoneDeserializer()
        {
            super(Timestamp.class);
        }

        @Override
        protected Timestamp _deserialize(String value, DeserializationContext context)
                throws JsonMappingException
        {
            return Timestamp.fromString(value);
        }
    }
}

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
embulk-0.6.27 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.26 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.25 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.24 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.23 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.22 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.21 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.20 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.19 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.18 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.17 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.16 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.15 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.14 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.13 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.12 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.11 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.10 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.9 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java
embulk-0.6.8 embulk-core/src/main/java/org/embulk/spi/time/TimestampSerDe.java