001/*-
002 * #%L
003 * Smile CDR - CDR
004 * %%
005 * Copyright (C) 2016 - 2025 Smile CDR, Inc.
006 * %%
007 * All rights reserved.
008 * #L%
009 */
010package ca.cdr.api.model.json;
011
012import com.fasterxml.jackson.core.JsonParser;
013import com.fasterxml.jackson.databind.DeserializationContext;
014import com.fasterxml.jackson.databind.JsonDeserializer;
015import com.fasterxml.jackson.databind.JsonNode;
016import com.fasterxml.jackson.databind.ObjectMapper;
017
018import java.io.IOException;
019
020/**
021 * Sometimes, the JSON received in the additionalJson property of the TransactionLogEventJson may be nested. This Custom deserializer helps
022 * prevent the JSON parse error: "Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)" from occurring when
023 * additionalJson is being deserialized.
024 */
025public class RawJsonDeserializer extends JsonDeserializer<String> {
026        private static final ObjectMapper mapper = new ObjectMapper();
027
028        @Override
029        public String deserialize(JsonParser theParser, DeserializationContext theDeserializationContext)
030                        throws IOException {
031                JsonNode node = mapper.readTree(theParser);
032                return mapper.writeValueAsString(node);
033        }
034}