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

com.clickzetta.platform.util.JsonParser Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.clickzetta.platform.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;
import com.clickzetta.platform.tools.LonghaulConf;
import com.clickzetta.platform.tools.WrapConf;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class JsonParser {

  private static final Logger LOG = LoggerFactory.getLogger(JsonParser.class);

  public WrapConf parserWrapConf(String jsonConfPath) throws IOException {
    String jsonString = FileUtils.readFileToString(new File(jsonConfPath), StandardCharsets.UTF_8);
    WrapConf conf = JSON.parseObject(jsonString, new TypeReference(){}, Feature.OrderedField);
    LOG.info("JSON Parser with path {} conf {}", jsonConfPath, conf);
    return conf;
  }

  public LonghaulConf parserLonghaulConf(String jsonConfPath) throws IOException {
    String jsonString = FileUtils.readFileToString(new File(jsonConfPath), StandardCharsets.UTF_8);
    LonghaulConf conf = JSON.parseObject(jsonString, new TypeReference(){}, Feature.OrderedField);
    LOG.info("JSON Parser with path {} conf {}", jsonConfPath, conf);
    return conf;
  }

  public static void main(String[] args) throws IOException {
    String path = ClassLoader.getSystemResource("conf.json").getPath();
    JsonParser jsonParser = new JsonParser();
    WrapConf conf = jsonParser.parserWrapConf(path);
    System.out.println(conf);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy