Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting MapList indent #43

Closed
HSGamer opened this issue Dec 21, 2020 · 2 comments
Closed

Formatting MapList indent #43

HSGamer opened this issue Dec 21, 2020 · 2 comments

Comments

@HSGamer
Copy link

HSGamer commented Dec 21, 2020

My code:

        Config config = new PluginConfig(this, "config.yml");

        if (config.getConfig().isSet("test-path"))
            config.getConfig().getMapList("test-path").forEach(map -> map.forEach((o, o2) -> System.out.println(o + ": " + o2)));

        List<Map<String, Object>> mapList = new ArrayList<>();

        Map<String, Object> map1 = new HashMap<>();
        map1.put("1", "test1");
        map1.put("2", "test2");
        map1.put("3", "test3");
        mapList.add(map1);
        Map<String, Object> map2 = new HashMap<>();
        map2.put("4", "test1");
        map2.put("5", "test2");
        map2.put("6", "test3");
        mapList.add(map2);
        Map<String, Object> map3 = new HashMap<>();
        map3.put("7", "test1");
        map3.put("8", "test2");
        map3.put("9", "test3");
        mapList.add(map3);
        config.getConfig().set("test-path", mapList);

        config.saveConfig();
  • When running this code, the file will be saved like this
test-path:
  -
  '1': test1
  '2': test2
  '3': test3
  -
  '4': test1
  '5': test2
  '6': test3
  -
  '7': test1
  '8': test2
  '9': test3
  • Instead of
test-path:
- '1': test1
  '2': test2
  '3': test3
- '4': test1
  '5': test2
  '6': test3
- '7': test1
  '8': test2
  '9': test3
  • A simple fix for this is to remove this line
@Carleslc
Copy link
Owner

This is the intended behaviour since version 1.7.1, where list indentation is the same as YamlConfiguration.options().indent() (2 by default).

Maybe an indentList option can be added to YamlConfigurationOptions to allow this customization.

@Carleslc Carleslc changed the title Parse issue with MapList Formatting MapList indent May 28, 2021
@Carleslc Carleslc added this to Next release (1.7.2) in Roadmap Feb 3, 2022
@Carleslc Carleslc removed this from Next release (1.7.3) in Roadmap Feb 3, 2022
@Carleslc Carleslc added this to Next release (1.7.3) in Roadmap Feb 3, 2022
@Carleslc
Copy link
Owner

Carleslc commented Feb 4, 2022

The default behaviour was not working properly, so the fix and the indentList option has been released in 1.7.3. See #52 for further details.

Now your example is formatted by default as follows:

test-path:
  - '1': test1
    '2': test2
    '3': test3
  - '4': test1
    '5': test2
    '6': test3
  - '7': test1
    '8': test2
    '9': test3

You can remove the extra indent to match your example expected output setting indentList to 0.

@Carleslc Carleslc closed this as completed Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants