Skip to content

YamlMapping.toString() generates incorrect structure when printing nested fields with same keys #635

@CoderYellow

Description

@CoderYellow

When parsing a YAML file that contains multiple nested path keys in different contexts, the output of YamlMapping.toString() incorrectly merges these fields, misrepresenting the actual structure.

✅ Input YAML

meta:
  credentials:
  - storage:
      path: /var/artipie/security1
      type: fs
    type: artipie
  repo_configs: repo
  storage:
    path: /var/artipie/
    type: fs

📋 Java Code

import com.amihaiemil.eoyaml.Yaml;
import com.amihaiemil.eoyaml.YamlMapping;

import java.io.File;
import java.io.IOException;

public class LocalTest {
    public static void main(String[] args) throws IOException {
        YamlMapping yamlMapping = Yaml.createYamlInput(new File(args[0])).readYamlMapping();
        System.out.println(yamlMapping);
    }
}

🧪 Expected Output

meta:
  credentials:
  - storage:
      path: /var/artipie/security1
      type: fs
    type: artipie
  repo_configs: repo
  storage:
    path: /var/artipie/
    type: fs

❌ Actual Output (Incorrect)

meta:
  credentials:
    -
      storage:
        path: /var/artipie/security1
        type: fs
      type: artipie
      path: /var/artipie/
  repo_configs: repo
  storage:
    path: /var/artipie/security1        # ← this is wrong
    type: fs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions