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

YAMLGenerator does not provide an option to preserve carriage return

Open lakshmi-udaan opened this issue 3 years ago • 2 comments

Question: Is there a way we can preserve carriage return while parsing yaml files? My yaml file looks like this:

keyA:
  subKeyAA: "some value"
  subKeyAB:
    subKeyABA: "again some value"
    
keyB:
  subKeyBA: "some value"
  subKeyBB: "something else"

keyC:
  subKeyCA: "some value"
  subKeyCB:
    - subKeyCBA: "again some value"

I'm reading the file as a Hashmap, making some changes & then dumping it again, but now it looks like this

keyA:
  subKeyAA: "changed value"
  subKeyAB:
    subKeyABA: "again some value"
keyB:
  subKeyBA: "changed value"
  subKeyBB: "something else"
keyC:
  subKeyCA: "changed value"
  subKeyCB:
    - subKeyCBA: "again some value"

but I want it to look it this:

keyA:
  subKeyAA: "changed value"
  subKeyAB:
    subKeyABA: "again some value"

keyB:
  subKeyBA: "changed value"
  subKeyBB: "something else"

keyC:
  subKeyCA: "changed value"
  subKeyCB:
    - subKeyCBA: "again some value"

I have tried enabling & disabling YAMLGenerator.Feature.SPLIT_LINES & YAMLGenerator.Feature.USE_PLATFORM_LINE_BREAKS but it doesn't seem to work.

Any help is appreciated.

lakshmi-udaan avatar Sep 08 '22 07:09 lakshmi-udaan

formatting details such as line feeds and comments can't really be preserved, they are not part of the data stream

yawkat avatar Sep 08 '22 12:09 yawkat

thankyou @yawkat for quick response.

lakshmi-udaan avatar Sep 09 '22 04:09 lakshmi-udaan