me.tomsdevsn.hetznercloud.deserialize.DateDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hetznercloud-java_2.12 Show documentation
Show all versions of hetznercloud-java_2.12 Show documentation
Java Integration to manage the Hetzner-Cloud
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);
}
}
}