PageRenderTime 71ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/important-library/src/main/java/com/github/yaml/YamlPractice.java

https://gitlab.com/doctorwho1986/doctor
Java | 33 lines | 24 code | 9 blank | 0 comment | 0 complexity | 0a6bf3e9cc9c1d7cfce49ee7d0c08452 MD5 | raw file
  1. package com.github.yaml;
  2. import java.io.InputStream;
  3. import java.util.Map;
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. import org.yaml.snakeyaml.Yaml;
  7. import com.alibaba.fastjson.JSON;
  8. public class YamlPractice {
  9. private static final Logger LOG = LoggerFactory.getLogger(YamlPractice.class);
  10. public static void main(String[] args) {
  11. Yaml yaml = new Yaml();
  12. InputStream inputStream = YamlPractice.class.getResourceAsStream("/importantLibraryYamlDefaultProp/jstorm.yaml");
  13. @SuppressWarnings("unchecked")
  14. Map<String, String> map = (Map<String, String>) yaml.load(inputStream);
  15. System.out.println(map);
  16. inputStream = YamlPractice.class.getResourceAsStream("/importantLibraryYamlDefaultProp/yamlPractice.yaml");
  17. ConfigPractice configPractice = yaml.loadAs(inputStream,ConfigPractice.class);
  18. System.out.println(JSON.toJSONString(configPractice));
  19. String dump = yaml.dump(configPractice);
  20. System.out.println(dump);
  21. LOG.info(dump);
  22. LOG.info(JSON.toJSONString(configPractice));
  23. }
  24. }