Skip to content

Commit

Permalink
more quality improvements from SonarLint (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkontyko authored Feb 24, 2024
1 parent 5db42e5 commit c2eb013
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.StringWriter;

public class DataFormatter {
private DataFormatter() { throw new IllegalStateException("Utility class"); }

public static String convertXmlToJsonString(String xml) throws JsonProcessingException {
return convertXmlToJsonNode(xml).toPrettyString();

Expand All @@ -42,7 +43,7 @@ private static JsonNode convertXmlToJsonNode(String xml) throws JsonProcessingEx
public static String convertJsonToXmlString(String json) throws ParserConfigurationException, TransformerException {
final var xmlDocument = convertJsonToXml(json);

final var transformer = TransformerFactory.newInstance().newTransformer();
final var transformer = SecureTransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");

Expand Down Expand Up @@ -114,7 +115,7 @@ private static void convertJsonNodeToXmlElement(
@NotNull JsonNode jsonNode) {

switch (jsonNode.getNodeType()) {
case OBJECT -> jsonNode.fields().forEachRemaining((entry) -> {
case OBJECT -> jsonNode.fields().forEachRemaining(entry -> {
final var childElement = xmlDocument.createElement(entry.getKey());
element.appendChild(childElement);
convertJsonNodeToXmlElement(xmlDocument, childElement, entry.getValue());
Expand Down Expand Up @@ -166,7 +167,7 @@ public static String generateJsonSchema(final String xml) throws JsonProcessingE

// recursing on the child nodes and feeding their schemas into the properties schema node
var sourceChildren = sourceNode.fields();
sourceChildren.forEachRemaining((entry) -> {
sourceChildren.forEachRemaining(entry -> {
var childSchema = generateJsonSchema(entry.getValue());
schemaObjectProperties.set(entry.getKey(), childSchema);
});
Expand Down

0 comments on commit c2eb013

Please sign in to comment.