com.conveyal.gtfs.util.json.JacksonSerializers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gtfs-lib Show documentation
Show all versions of gtfs-lib Show documentation
A library to load and index GTFS feeds of arbitrary size using disk-backed storage
package com.conveyal.gtfs.util.json;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.google.common.io.BaseEncoding;
import org.mapdb.Fun.Tuple2;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
//import java.time.format.D;
public class JacksonSerializers {
public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
/** serialize local dates as noon GMT epoch times */
public static class LocalDateStringSerializer extends StdScalarSerializer {
public LocalDateStringSerializer() {
super(LocalDate.class, false);
}
@Override
public void serialize(LocalDate ld, JsonGenerator jgen, SerializerProvider arg2) throws IOException {
String dateString = FORMATTER.format(ld);
jgen.writeString(dateString);
}
}
/** deserialize local dates from GMT epochs */
public static class LocalDateStringDeserializer extends StdScalarDeserializer {
public LocalDateStringDeserializer () {
super(LocalDate.class);
}
@Override
public LocalDate deserialize(JsonParser jp, DeserializationContext arg1) throws IOException {
LocalDate date = LocalDate.parse(jp.getValueAsString(), FORMATTER);
return date;
}
}
public static class MyDtoNullKeySerializer extends StdSerializer
© 2015 - 2025 Weber Informatics LLC | Privacy Policy