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

uk.gov.service.payments.commons.api.json.MicrosecondPrecisionDateTimeDeserializer Maven / Gradle / Ivy

There is a newer version: 1.0.20241120144934
Show newest version
package uk.gov.service.payments.commons.api.json;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class MicrosecondPrecisionDateTimeDeserializer extends StdDeserializer {

    public static final DateTimeFormatter MICROSECOND_FORMATTER =
            MicrosecondPrecisionDateTimeSerializer.MICROSECOND_FORMATTER;

    public MicrosecondPrecisionDateTimeDeserializer() {
        this(null);
    }

    @Override
    public ZonedDateTime deserialize(JsonParser p, DeserializationContext ctxt) {
        try {
            return ZonedDateTime.from(MICROSECOND_FORMATTER.parse(p.getText()));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private MicrosecondPrecisionDateTimeDeserializer(Class t) {
        super(t);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy