package com.ejie.aa21b.util;

/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  com.ejie.x38.util.DateTimeManager
 *  org.codehaus.jackson.JsonLocation
 *  org.codehaus.jackson.JsonParseException
 *  org.codehaus.jackson.JsonParser
 *  org.codehaus.jackson.JsonProcessingException
 *  org.codehaus.jackson.map.DeserializationContext
 *  org.codehaus.jackson.map.JsonDeserializer
 *  org.springframework.context.i18n.LocaleContextHolder
 *  org.springframework.stereotype.Component
 */

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

import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.DeserializationContext;
import org.codehaus.jackson.map.JsonDeserializer;
import org.springframework.stereotype.Component;

@Component
public class JsonDateDeserializer extends JsonDeserializer<Date> {
	public Date deserialize(JsonParser par, DeserializationContext ctx)
			throws IOException, JsonProcessingException {
		SimpleDateFormat format;
		String dateText;

		try {
			dateText = par.getText();

			if (dateText == null || "".equals(dateText))

				return null;
			else if (dateText.indexOf("/") == 4)
				format = new SimpleDateFormat("yyyy/MM/dd");
			else
				format = new SimpleDateFormat("dd/MM/yyyy");
			// System.out.println(dateText);
			Date kk = format.parse(dateText);
			// System.out.println(kk);
			return kk;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
}