Skip to content

Instantly share code, notes, and snippets.

Last active September 16, 2020 18:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Exposing DumperOptions in Jackson's YAML handling.
// See article for context:
// Licensed under the MIT license described here:
// Copyright (c) Square, Inc.
val jacksonMapper = YAMLMapper(MyYAMLFactory()).apply {
// I left the constructor parameters nullable deliberately
class MyYAMLGenerator(
ctx: IOContext?,
jsonFeatures: Int,
yamlFeatures: Int,
codec: ObjectCodec,
out: Writer?,
version: DumperOptions.Version?
): YAMLGenerator(ctx, jsonFeatures, yamlFeatures, codec, out, version) {
override fun buildDumperOptions(
jsonFeatures: Int,
yamlFeatures: Int,
version: Version?
): DumperOptions {
return super.buildDumperOptions(jsonFeatures, yamlFeatures, version).apply {
defaultScalarStyle = ScalarStyle.LITERAL;
defaultFlowStyle = FlowStyle.BLOCK
indicatorIndent = 2
nonPrintableStyle = ESCAPE
indent = 4
isPrettyFlow = true
width = 100
this.version = version
class MyYAMLFactory(): YAMLFactory() {
override fun _createGenerator(out: Writer, ctxt: IOContext): YAMLGenerator {
val feats = _yamlGeneratorFeatures
return MyYAMLGenerator(ctxt, _generatorFeatures, feats, _objectCodec, out, _version)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment