Quantcast
Viewing all articles
Browse latest Browse all 39

Answer by Chris for Jackson YAML Serialization Object Arrays Format

In today's environment using at least version 2.12.x of jackson-dataformat-yaml thanks to the introduction of YAMLGenerator.Feature.INDENT_ARRAYS_WITH_INDICATOR, you can simply just do:

public ObjectMapper yamlObjectMapper() {    final YAMLFactory factory = new YAMLFactory()            .enable(YAMLGenerator.Feature.INDENT_ARRAYS_WITH_INDICATOR)            .enable(YAMLGenerator.Feature.MINIMIZE_QUOTES)            .disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER);    return new ObjectMapper(factory);}

Which will give you the output of:

employees: - name: John   age: 26 - name: Bill   age: 17

Viewing all articles
Browse latest Browse all 39

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>