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.databind.DeserializationContext;
015import com.fasterxml.jackson.databind.JsonDeserializer;
016import org.hl7.fhir.dstu3.model.DateTimeType;
017
018import java.io.IOException;
019import java.util.Date;
020
021import static org.apache.commons.lang3.StringUtils.isNotBlank;
022
023public class JsonDateWithEmptyDeserializer extends JsonDeserializer<Date> {
024
025        @Override
026        public Date deserialize(JsonParser theJsonParser, DeserializationContext theContext) throws IOException {
027                String string = theJsonParser.getValueAsString();
028                if (string.isEmpty()) {
029                        return new Date(0L);
030                }
031                if (isNotBlank(string)) {
032                        return new DateTimeType(string).getValue();
033                }
034                return null;
035        }
036}