FasterXML / jackson-dataformats-text

Uber-project for (some) standard Jackson textual format backends: csv, properties, yaml (xml to be added in future)
Apache License 2.0
406 stars 149 forks source link

.without(YAMLGenerator.Feature.WRITE_DOC_START_MARKER) seems to be ignored #215

Open jdimeo opened 4 years ago

jdimeo commented 4 years ago

I feel like I may be using the APIs incorrectly, but I can't figure out what I'm doing wrong. The following code:

new YAMLMapper()
    .writer()
    .without(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)
    .writeValueAsString(o)

still puts the --- at the beginning of the string.

I'm using version 2.11.2

P.S. YAML support is a game. changer. Huge fan and huge thanks!

cowtowncoder commented 4 years ago

Hmmh. Yes, that looks like it ought to prevent start marker from being written. Thank you for reporting this, I will need to have a look!

One thing that might help is if you could try a work-around of explicitly creating YAMLFactory, configuring setting, constructing YAMLMapper with it -- I suspect this might be related to writer not applying settings correctly.

cowtowncoder commented 4 years ago

Ok, I can reproduce this issue. I also realized that it may be tricky to fix with 2.x, the problem being that the document start marker is being written during construction of YAMLGenerator whereas ObjectWriter passes its settings right after construction but (supposedly) before actual output. 3.x (master) solves this initialization problem but that required bigger refactoring.

I'll have to think of how to tackle this.

You may be able to work around this issue by pre-configuring YAMLFactory however:

YAMLMapper mapper = new YAMLMapper(YAMLFactory.builder()
    .disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)).build());

in which case setting is used as expected.

jdimeo commented 4 years ago

Thank you so much for your fast response! I can definitely wait for 3.x and/or use YAMLFactory in the meantime.

cowtowncoder commented 4 years ago

Ok good. I hope I'll address this for 2.12(.0).

cowtowncoder commented 1 year ago

Unfortunately it seems unlikely this can be fixed for 2.x.

Work-around mentioned above does, however, work: that is, configuring YAMLFactory directly works