001package ca.cdr.api.model.json;
002
003/*
004 * #%L
005 * Smile CDR - CDR
006 * %%
007 * Copyright (C) 2016 - 2024 Smile CDR, Inc.
008 * %%
009 * All rights reserved.
010 * #L%
011 */
012
013import com.fasterxml.jackson.core.JsonParser;
014import com.fasterxml.jackson.core.JsonProcessingException;
015import com.fasterxml.jackson.databind.DeserializationContext;
016import com.fasterxml.jackson.databind.JsonDeserializer;
017import org.hl7.fhir.dstu3.model.DateTimeType;
018
019import java.io.IOException;
020import java.util.Date;
021
022import static org.apache.commons.lang3.StringUtils.isNotBlank;
023
024public class JsonDateDeserializer extends JsonDeserializer<Date> {
025
026        @Override
027        public Date deserialize(JsonParser theP, DeserializationContext theCtxt)
028                        throws IOException, JsonProcessingException {
029                String string = theP.getValueAsString();
030                if (isNotBlank(string)) {
031                        return new DateTimeType(string).getValue();
032                }
033                return null;
034        }
035}