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

com.droidlogix.dbflare.a2e.DbFlareDateDeserializer Maven / Gradle / Ivy

There is a newer version: 1.0.8
Show newest version
package com.droidlogix.dbflare.a2e;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Type;
import java.util.Date;

public class DbFlareDateDeserializer implements JsonDeserializer
{
	private static final Logger logger = LoggerFactory.getLogger(DbFlareDateDeserializer.class);

	@Override
	public Object deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException
	{
		try
		{
			return new Date(jsonElement.getAsJsonPrimitive().getAsLong());
		}
		catch (Exception exception1)
		{
			logger.error(exception1.getMessage());
			try
			{
				return new DateTime(jsonElement.getAsString()).toDate();
			}
			catch(Exception exception2)
			{
				logger.error(exception2.getMessage());
			}
		}
		return null;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy