When creating objectMapper with yaml factory there are couple of configuration parameters which you can set:
ObjectMapper o = new ObjectMapper(new YAMLFactory());
// o.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
// o.enable(SerializationFeature.CLOSE_CLOSEABLE);
problem is that this configuration is ignored in YAML Generator:
@Override
public void close() throws IOException
{
if (!isClosed()) {
_emitter.emit(new DocumentEndEvent(null, null, false));
_emitter.emit(new StreamEndEvent(null, null));
super.close();
_writer.close();
}
}
even when in javadoc is written something else
void com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.close() throws IOException
Method called to close this generator, so that no more content can be written.
Whether the underlying target (stream, writer) gets closed depends on whether this generator either manages the target (i.e. is the only one with access to the target -- case if caller passes a reference to the resource such as File, but not stream); or has feature Feature.AUTO_CLOSE_TARGET enabled. If either of above is true, the target is also closed. Otherwise (not managing, feature not enabled), target is not closed.