
org.sonar.plugins.secrets.configuration.deserialization.MatchDeserializer Maven / Gradle / Ivy
/*
* SonarQube Text Plugin
* Copyright (C) 2021-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Sonar Source-Available License for more details.
*
* You should have received a copy of the Sonar Source-Available License
* along with this program; if not, see https://sonarsource.com/license/ssal/
*/
package org.sonar.plugins.secrets.configuration.deserialization;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import java.io.IOException;
import java.util.Iterator;
import org.sonar.plugins.secrets.configuration.model.matching.AuxiliaryPattern;
import org.sonar.plugins.secrets.configuration.model.matching.BooleanCombination;
import org.sonar.plugins.secrets.configuration.model.matching.Match;
public class MatchDeserializer extends JsonDeserializer {
@Override
public Match deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);
JsonParser matchNodeParser = treeNode.traverse();
matchNodeParser.setCodec(jsonParser.getCodec());
Iterator nodeIterator = treeNode.fieldNames();
// As the yaml is validated before, there is always one element
String name = nodeIterator.next();
if (name.startsWith("pattern")) {
return matchNodeParser.readValueAs(AuxiliaryPattern.class);
} else {
return matchNodeParser.readValueAs(BooleanCombination.class);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy