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

ec.gob.senescyt.sniese.commons.deserializers.JSONFechaDeserializer Maven / Gradle / Ivy

There is a newer version: 2.0.5
Show newest version
package ec.gob.senescyt.sniese.commons.deserializers;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import ec.gob.senescyt.sniese.commons.Constantes;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.io.IOException;

public class JSONFechaDeserializer extends JsonDeserializer {

    DateTimeFormatter fmt = DateTimeFormat.forPattern(Constantes.DATE_FORMAT);

    @Override
    public DateTime deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException {
        String fechaSerializada = jsonParser.getText();
        if (fechaSerializada.isEmpty()) {
            return null;
        }
        return fmt.parseDateTime(fechaSerializada).withZone(DateTimeZone.UTC).withTimeAtStartOfDay();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy