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