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

io.konik.sdk.json.DateTimeDeserializer Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
package io.konik.sdk.json;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

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

public class DateTimeDeserializer extends JsonDeserializer {
	private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm");

	@Override
	public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
		String dateAsString = jsonParser.readValueAs(String.class);
		Date date = null;
		try {
			date = DATE_FORMAT.parse(dateAsString);
		} catch (ParseException e) {
			throw new RuntimeException(e);
		}

		return date;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy