ilmoeuro / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
0 stars 0 forks source link

extra braces while dumping map data as yaml #37

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Running the following program 

    Map<String, Object> data = new HashMap<String, Object>();
    data.put("name", "Silenthand Olleander");
    data.put("race", "Human");
    data.put("race1", "0.001");
    // data.put("traits", new String[] { "ONE_HAND", "ONE_EYE" });

    Yaml yaml = new Yaml();
    String output = yaml.dump(data);
    System.out.println(output);

Output1 is "{race1: '0.001', race: Human, name: Silenthand Olleander}"
2.
    Map<String, Object> data = new HashMap<String, Object>();
    data.put("name", "Silenthand Olleander");
    data.put("race", "Human");
    data.put("race1", "0.001");
    data.put("traits", new String[] { "ONE_HAND", "ONE_EYE" });

    Yaml yaml = new Yaml();
    String output = yaml.dump(data);
    System.out.println(output);

OutPut2 is "
traits: [ONE_HAND, ONE_EYE]
race1: '0.001'
race: Human
name: Silenthand Olleander"

What is the expected output? What do you see instead?
Why output1 has braces ? If i have to remove braces then i have to add 
the  following in data

    data.put("traits", new String[] { "ONE_HAND", "ONE_EYE" });

What version of the product are you using? On what operating system?

Windows XP , Java - 1.5.10 , Snake Yaml Version  - snake yaml 1.0
Please provide any additional information below.

Original issue reported on code.google.com by ashish...@gmail.com on 3 Dec 2009 at 8:55

GoogleCodeExporter commented 9 years ago
please check FAQ here: http://code.google.com/p/snakeyaml/wiki/Documentation

By default, SnakeYAML chooses the style of a collection depending on whether it 
has 
nested collections. If a collection has nested collections, it will be assigned 
the 
block style. Otherwise it will have the flow style.

More info for the style is here: 
http://yaml.org/spec/1.1/#flow%20style/information%20model

You can define the style (block or flow) in the DumperOptions.

Original comment by py4fun@gmail.com on 4 Dec 2009 at 8:18