uk.gov.service.payments.commons.api.json.ExternalMetadataDeserialiser Maven / Gradle / Ivy
package uk.gov.service.payments.commons.api.json;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonMappingException;
import uk.gov.service.payments.commons.model.charge.ExternalMetadata;
import java.io.IOException;
import java.util.Map;
public class ExternalMetadataDeserialiser extends JsonDeserializer {
@Override
public ExternalMetadata deserialize(final JsonParser jsonParser, final DeserializationContext ctxt) throws IOException {
if (!jsonParser.isExpectedStartObjectToken()){
throw new JsonMappingException(jsonParser, "Field [metadata] must be an object of JSON key-value pairs");
}
Map metadata = jsonParser.getCodec().readValue(jsonParser, new TypeReference