snakeyaml

Spring Boot: read list from yaml using @Value or @ConfigurationProperties

[亡魂溺海] 提交于 2019-12-30 00:58:10
问题 I want to read a list of hosts from a yaml file (application.yml), the file looks like this: cors: hosts: allow: - http://foo1/ - http://foo2/ - http://foo3/ (Example 1) My class used defines the value like this: @Value("${cors.hosts.allow}") List<String> allowedHosts; But reading fails as Spring complains about this: java.lang.IllegalArgumentException: Could not resolve placeholder 'cors.hosts.allow' in string value "${cors.hosts.allow}" When I change the file like this the property can be

SnakeYAML low-level API not parsing MapNode correctly

こ雲淡風輕ζ 提交于 2019-12-24 06:31:08
问题 I wanted to do some processing on values in yml file. Someone suggested me to use snakeYAML's low-level API for this purpose. So I've written some code using that but I'm pretty much stuck due to the following reasons. Here's the code I've wrote: public static void main(String[] args) throws Exception{ Yaml yaml = new Yaml(); FileReader contentFromFile=new FileReader("/Users/prakash.tiwari/Desktop/yamlInput.yml"); for (Node node : yaml.composeAll(contentFromFile)) { System.out.println(node);

Parsing yaml file using snakeyaml with integer as key

可紊 提交于 2019-12-23 23:51:06
问题 I am trying to parse a yaml file that I did not create, and one that I cannot edit. The structure of the file is 681: activities: copying: time: 480 manufacturing: materials: - quantity: 86 typeID: 38 products: - quantity: 1 typeID: 165 time: 600 research_material: time: 210 research_time: time: 210 blueprintTypeID: 681 maxProductionLimit: 300 The file is ~144,000 lines in length, each following the aforementioned structure. The problem I'm having is, because it's being parsed into POJOs

SnakeYAML by example

China☆狼群 提交于 2019-12-23 04:52:07
问题 I am trying to read and parse a YAML file with SnakeYAML and turn it into a config POJO for my Java app: // Groovy pseudo-code class MyAppConfig { List<Widget> widgets String uuid boolean isActive // Ex: MyAppConfig cfg = new MyAppConfig('/opt/myapp/config.yaml') MyAppConfig(String configFileUri) { this(loadMap(configFileUri)) } private static HashMap<String,HashMap<String,String>> loadConfig(String configFileUri) { Yaml yaml = new Yaml(); HashMap<String,HashMap<String,String>> values try {

How to hide bean type in snakeyaml

时光毁灭记忆、已成空白 提交于 2019-12-22 06:56:07
问题 This code will output:(YAML) --- !!org.test.bean.Person address: 4011 16th Ave S ..... Can hide my bean type(org.test.bean.Person) anyway !? (prefer to use snakeyaml config...i can't find it..) thanks!! public static void dumpYAML(){ Constructor constructor = new Constructor(Person.class); TypeDescription personDescription = new TypeDescription(Person.class); personDescription.putListPropertyType("phone", Tel.class); constructor.addTypeDescription(personDescription); Yaml yaml = new Yaml

gpg: Sorry, no terminal at all requested - can't get input

南笙酒味 提交于 2019-12-21 02:07:09
问题 When decrypting I get following error: $ eyaml decrypt -s 'ENC and the key goes on here' .gnupg --quiet --no-secmem-warning --no-permission-warning --no-tty --yes --decrypt) failed with: gpg: Sorry, no terminal at all requested - can't get input I have checked my keys, everything is in order. At this point I am out of options. 回答1: If you configured Automatic Git commit signing with GPG on macOS and you see this error comment out no-tty in ~/.gnupg/gpg.conf as suggested by Fahl-Design. This

groovy load YAML file modify and write it in a file

こ雲淡風輕ζ 提交于 2019-12-19 10:18:03
问题 I have YMAL files, using groovy I want to read and modify one element value, then write it into another file. Playing with this code, trying to modify first filevalue from TopClass.py to changeclass.py. But its not modifying the value. import org.yaml.snakeyaml.Yaml class Test{ def static main(args){ Yaml yaml = new Yaml() def Map map = (Map) yaml.load(data) println map.Stack.file[0] map.Stack.file[0]='changeclass.py' println map.Stack.file[0] } def static String data=""" Date: 2001-11-23 15

Passing external yml file in my spark-job/code not working throwing “Can't construct a java object for tag:yaml.org,2002”

流过昼夜 提交于 2019-12-17 14:32:27
问题 I am using spark 2.4.1 version and java8. I am trying to load external property file while submitting my spark job using spark-submit. As I am using below TypeSafe to load my property file. <groupId>com.typesafe</groupId> <artifactId>config</artifactId> <version>1.3.1</version> In my spark driver class MyDriver.java I am loading the YML file as below String ymlFilename = args[1].toString(); Optional<QueryEntities> entities = InputYamlProcessor.process(ymlFilename); I have all code here

Passing external yml file in my spark-job/code not working throwing “Can't construct a java object for tag:yaml.org,2002”

二次信任 提交于 2019-12-17 14:31:32
问题 I am using spark 2.4.1 version and java8. I am trying to load external property file while submitting my spark job using spark-submit. As I am using below TypeSafe to load my property file. <groupId>com.typesafe</groupId> <artifactId>config</artifactId> <version>1.3.1</version> In my spark driver class MyDriver.java I am loading the YML file as below String ymlFilename = args[1].toString(); Optional<QueryEntities> entities = InputYamlProcessor.process(ymlFilename); I have all code here

Get Integer[] instead of ArrayList<Integer> from YAML file

帅比萌擦擦* 提交于 2019-12-13 06:35:10
问题 I am parsing a YAML file Props: Prop1 : [10, 22, 20] Prop2 : [20, 42, 60] This gives me Map<String, Map<String, ArrayList<Integer>>> I would like to get Map<String, Map<String, Integer[]>> I do not want to convert List<Integer> to Integer[] in the code that reads the file. Can I change something in my YAML file? 回答1: In contrast to my other answer, this one focuses on changing the YAML file. However, you also need to add some Java code to tell SnakeYaml how to load the tag you use. You could