jackson-dataformats-text icon indicating copy to clipboard operation
jackson-dataformats-text copied to clipboard

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

Open jdimeo opened this issue 5 years ago • 5 comments

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!

jdimeo avatar Aug 13 '20 20:08 jdimeo

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 avatar Aug 13 '20 21:08 cowtowncoder

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.

cowtowncoder avatar Aug 14 '20 01:08 cowtowncoder

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

jdimeo avatar Aug 14 '20 01:08 jdimeo

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

cowtowncoder avatar Aug 14 '20 01:08 cowtowncoder

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

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

cowtowncoder avatar Aug 25 '23 03:08 cowtowncoder