package com.krishagni.catissueplus.core.common.util;

import java.io.IOException;
import java.time.Instant;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

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


public class JsonDateDeserializer extends UntypedObjectDeserializer {
	private Log logger = LogFactory.getLog(JsonDateDeserializer.class);

	@Override
	public Object deserialize(JsonParser p, DeserializationContext ctxt)
	throws IOException {
		Object ret;

		if (p.getCurrentToken() == JsonToken.VALUE_STRING) {
			try {
				if (StringUtils.isBlank(p.getText())) {
					ret = null;
				} else {
					ret = DateUtils.parseDate(p.getText(), "yyyy-MM-dd");
				}
			} catch (Exception e) {
				try {
					ret = Date.from(Instant.parse(p.getText()));
				} catch (Exception e1) {
					ret = super.deserialize(p, ctxt);
				}
			}
		} else if (p.getCurrentToken() == JsonToken.VALUE_NUMBER_INT) {
			try {
				ret = new Date(p.getLongValue());
			} catch (Exception e) {
				ret = super.deserialize(p, ctxt);
			}
		} else {
			ret = super.deserialize(p, ctxt);
		}

		logger.info("Input date " + p.getText() + " deserialized to " + ret);
		return ret;
	}
}

@@ -1107,24 +1107,117 @@
 ption e1) %7B%0A
+%09%09%09%09%09try %7B%0A%09%09%09%09%09%09ret = new Date(Long.parseLong(p.getText()));%0A%09%09%09%09%09%7D catch (Exception e2) %7B%0A%09
 %09%09%09%09%09ret = s
@@ -1243,16 +1243,23 @@
  ctxt);%0A
+%09%09%09%09%09%7D%0A
 %09%09%09%09%7D%0A%09%09

Handle the date/time submitted as integer string of milliseconds elapsed since Epoch.