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