001package ca.cdr.api.model.json.jackson2deprecated; 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 ca.cdr.api.model.json.JsonDateWithEmptyDeserializer; 014import com.fasterxml.jackson.core.JsonParser; 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 024/** 025 * Jackson 2 copy of {@link JsonDateWithEmptyDeserializer}, retained only for the admin-JSON Spring MVC wire: 026 * Spring 6.2's {@code MappingJackson2HttpMessageConverter} accepts a Jackson 2 {@code ObjectMapper} only, 027 * and Spring provides no Jackson 3 converter before Spring Framework 7. 028 * <p> 029 * TODO SPRING_7_UPGRADE - delete this class once Spring is upgraded to 7 and 030 * {@code JacksonJsonHttpMessageConverter} can take the Jackson 3 mapper directly. Keep it in step with 031 * {@link JsonDateWithEmptyDeserializer} until then. 032 */ 033public class JsonDateWithEmptyDeserializerJacksonV2Deprecated extends JsonDeserializer<Date> { 034 035 @Override 036 public Date deserialize(JsonParser theJsonParser, DeserializationContext theContext) throws IOException { 037 String string = theJsonParser.getValueAsString(); 038 if (string.isEmpty()) { 039 return new Date(0L); 040 } 041 if (isNotBlank(string)) { 042 return new DateTimeType(string).getValue(); 043 } 044 return null; 045 } 046}