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.JsonDateSerializer;
014import com.fasterxml.jackson.core.JsonGenerator;
015import com.fasterxml.jackson.databind.JsonSerializer;
016import com.fasterxml.jackson.databind.SerializerProvider;
017import org.hl7.fhir.dstu3.model.InstantType;
018
019import java.io.IOException;
020import java.util.Date;
021
022/**
023 * Jackson 2 copy of {@link JsonDateSerializer}, retained only for the admin-JSON Spring MVC wire:
024 * Spring 6.2's {@code MappingJackson2HttpMessageConverter} accepts a Jackson 2 {@code ObjectMapper} only,
025 * and Spring provides no Jackson 3 converter before Spring Framework 7.
026 * <p>
027 * TODO SPRING_7_UPGRADE - delete this class once Spring is upgraded to 7 and
028 * {@code JacksonJsonHttpMessageConverter} can take the Jackson 3 mapper directly. Keep it in step with
029 * {@link JsonDateSerializer} until then.
030 */
031public class JsonDateSerializerJacksonV2Deprecated extends JsonSerializer<Date> {
032
033        @Override
034        public void serialize(Date theValue, JsonGenerator theGen, SerializerProvider theSerializers) throws IOException {
035                if (theValue != null) {
036                        theGen.writeString(new InstantType(theValue).getValueAsString());
037                }
038        }
039}