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.JsonDateDeserializer;
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 JsonDateDeserializer}, 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 JsonDateDeserializer} until then.
032 */
033public class JsonDateDeserializerJacksonV2Deprecated extends JsonDeserializer<Date> {
034
035        @Override
036        public Date deserialize(JsonParser theP, DeserializationContext theCtxt) throws IOException {
037                String string = theP.getValueAsString();
038                if (isNotBlank(string)) {
039                        return new DateTimeType(string).getValue();
040                }
041                return null;
042        }
043}