package com.github.blindpirate.gogradle.util;

import com.ctc.wstx.stax.WstxInputFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import java.io.File;
import java.io.IOException;

import static com.ctc.wstx.api.WstxInputProperties.PARSING_MODE_DOCUMENTS;
import static com.github.blindpirate.gogradle.util.ExceptionHandler.uncheckException;

public class DataExchange {
    private static final ObjectMapper JSON_MAPPER = new ObjectMapper();
    private static final ObjectMapper YAML_MAPPER = new ObjectMapper(new YAMLFactory());
    private static XmlMapper XML_MAPPER;

    static {
        // Override the default config, otherwise it will not ignore <?xml ...>
        WstxInputFactory inputFactory = new WstxInputFactory();
        inputFactory.getConfig().setInputParsingMode(PARSING_MODE_DOCUMENTS);
        XML_MAPPER = new XmlMapper(inputFactory);
    }

    public static <T> T parseJson(File file, Class<T> clazz) {
        return parseWithMapper(JSON_MAPPER, file, clazz);
    }

    public static <T> T parseJson(String str, Class<T> clazz) {
        return parseWithMapper(JSON_MAPPER, str, clazz);
    }

    public static <T> T parseYaml(File file, Class<T> clazz) {
        return parseWithMapper(YAML_MAPPER, file, clazz);
    }

    public static <T> T parseXml(File file, Class<T> clazz) {
        return parseWithMapper(XML_MAPPER, file, clazz);
    }

    private static <T> T parseWithMapper(ObjectMapper mapper, String s, Class<T> clazz) {
        try {
            return mapper.readValue(s, clazz);
        } catch (IOException e) {
            throw uncheckException(e);
        }
    }

    private static <T> T parseWithMapper(ObjectMapper mapper, File file, Class<T> clazz) {
        try {
            return mapper.readValue(file, clazz);
        } catch (IOException e) {
            throw uncheckException(e);
        }
    }

    public static String toYaml(Object model) {
        try {
            return YAML_MAPPER.writeValueAsString(model);
        } catch (JsonProcessingException e) {
            throw uncheckException(e);
        }
    }
}

@@ -738,26 +738,25 @@
 lMapper 
-XML_MAPPER
+xmlMapper
 ;%0A%0A    s
@@ -993,26 +993,25 @@
         
-XML_MAPPER
+xmlMapper
  = new X
@@ -1522,18 +1522,17 @@
 per(
-XML_MAPPER
+xmlMapper
 , fi

Fix style