All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aeontronix.enhancedmule.tools.util.JacksonHelper Maven / Gradle / Ivy

There is a newer version: 2.0.0-alpha4
Show newest version
/*
 * Copyright (c) 2023. Aeontronix Inc
 */

package com.aeontronix.enhancedmule.tools.util;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.javaprop.JavaPropsMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

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

public class JacksonHelper {
    public static JsonNode readTree(File file) throws IOException {
        String fname = file.getName().toLowerCase();
        if (fname.endsWith(".json")) {
            return new ObjectMapper().readTree(file);
        } else if (fname.endsWith(".yaml") || fname.endsWith(".yml")) {
            return new ObjectMapper(new YAMLFactory()).readTree(file);
        } else if (fname.endsWith(".properties")) {
            return new JavaPropsMapper().readTree(file);
        } else {
            throw new IllegalArgumentException("Unsupported file type: " + file);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy