- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 152
 
Open
Labels
yamlIssue related to YAML format backendIssue related to YAML format backend
Description
Hi,
Description
currently I am using Jackson with dataformat-yaml to sort my yaml files by key:
 final YAMLFactory yamlFactory = new YAMLFactory()
        .disable(YAMLGenerator.Feature.SPLIT_LINES)
        .disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)
        ;
    this.objectMapper = new ObjectMapper(yamlFactory)
        .registerModule(new Jdk8Module())
        .setDefaultPrettyPrinter(new DefaultPrettyPrinter())
        .configure(SerializationFeature.INDENT_OUTPUT, true)
        .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
        .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, orderMapEntriesByKeys)
    ;
Now, comments will get lost regardless of which method I use to read and write the document.
SnakeYAML features
However, with SnakeYAML alone you could do something like this:
- Create a new Reader/Writer which preserves comments: https://stackoverflow.com/a/76975195/1549977
 - Create a custom Representer which sorts keys: https://stackoverflow.com/a/63095199/1549977
 
Wishlist
Ideally, a comment above a key in the same indentation level stays with the key. If it is the same indentation level as the previous element, keep it below that one.
Can this be done in Jackson with dataformat-yaml?
jimtng
Metadata
Metadata
Assignees
Labels
yamlIssue related to YAML format backendIssue related to YAML format backend