3

If I use a YAMLFactory instead of default one (JSON) for ObjectMapper and configure a custom indentation, the indentation is not taken into account

If I don't use YAML output, it works for the JSON output.

Any idea ?

DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter("    ", DefaultIndenter.SYS_LF);

DefaultPrettyPrinter printer = new DefaultPrettyPrinter();
printer.indentObjectsWith(indenter);
printer.indentArraysWith(indenter);

ObjectMapper objectMapper = new ObjectMapper( new YAMLFactory() );

objectMapper.setDefaultPrettyPrinter(printer);

objectMapper.enable(SerializationFeature.INDENT_OUTPUT);

String string = objectMapper.writeValueAsString(myObject);
Mike Marquet
  • 124
  • 1
  • 7
  • This looks more like an issue that should be reported to ObjectMapper than a question that leads to useful answers. – flyx Oct 27 '17 at 12:04
  • By the way, you usually get tighter control of output by using the SnakeYaml API itself compared to using a wrapper library like this one – I don't understand why people use this Jackson stuff when they just want to serialize objects to YAML. SnakeYaml does that pretty well and the API has the same level. – flyx Oct 27 '17 at 12:07

0 Answers0