FasterXML / FasterXML/jackson-dataformats-text
FeatureRequest: Add PRESERVE_COMMENTS feature for SnakeYAML > 2.0
- Dominant language
- Java
- Stars
- 455
- Forks
- 164
- Avg merge
- 6d 10h
- Merged PRs (30d)
- 2
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:
1. Create a new Reader/Writer which preserves comments: https://stackoverflow.com/a/76975195/1549977
2. 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?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.