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

me.tomsdevsn.hetznercloud.deserialize.DateDeserializer Maven / Gradle / Ivy

The newest version!
package me.tomsdevsn.hetznercloud.deserialize;

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

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateDeserializer extends StdDeserializer {

    private static final long serialVersionUID = 1L;
    private SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");

    public DateDeserializer() {
        this(null);
    }

    public DateDeserializer(Class vc) {
        super(vc);
    }

    @Override
    public Date deserialize(JsonParser jsonParser, DeserializationContext context) {
        try {
            String date = jsonParser.getText();
            return formatter.parse(date);
        } catch (IOException | ParseException ex) {
            throw new RuntimeException(ex);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy