1

I am trying to modify following type of yaml file, but I have problem when i dump it. Problem is in those quote marks which represent string i guess. I know there is DumperOption to setDefaultScalarStyle, but when i use it with any of Styles used U cant get same style as I have in input yaml file. Am i missing something?

original 
   parameters:
      continent: "Africa"
      image: african_set
      machines: {
        1: "vm1",
        2: "vm1" }
      routes: {
         first: {
          1: "21 via 43 dot gi",
          2: "43 via 46 dgt ll" },
        second: {
          1: "61 via 03 d ghji",
          2: "83 via 96 t llhh" }
      }
      protocol: {
        "version": "1.94",
        "machines": ["m11", "m23"],
            "connections": [
                    {
                            "name": "t1",
                            "Type": {
                                    "ID": 01
                            },
                            "service": {
                                    "ID": 1,
                                    "net_type": 1
                            }
                    }

....

example of using DOUBLE_QUOTE

{
  "parameters": {
    "continent": "Africa",
    "image": "african_set",
    "machines": {
      !!int "1": "vm1",
      !!int "2": "vm2",
      !!int "3": "vm3"
    }, 
    "routes": {
      "first": {
        !!int "1": "21 via 43 dot gi",
        !!int "2": "43 via 46 dgt ll"
      },
      "second": {
        !!int "1": "61 via 03 d ghji",
        !!int "2": "83 via 96 t llhh"
      }
    },
Hülya
  • 3,353
  • 2
  • 12
  • 19
Sirke
  • 33
  • 8
  • Does this answer your question? [Dumping values with quotes with SnakeYaml](https://stackoverflow.com/questions/55268892/dumping-values-with-quotes-with-snakeyaml) – flyx Mar 27 '20 at 11:40
  • I understand that in my case i want to use StringWriter instead PrintWriter, but I dont know how to get Iterator events, I have object I get from yaml.load(yamlFileContent) which i edit and want save. – Sirke Mar 27 '20 at 14:21
  • `yaml.load` is the high-level API mentioned in the linked answer and causes a loss of all presentation-related information (including quoting details). If you want to keep that information, you can't use it. – flyx Mar 27 '20 at 14:53
  • So if i cant do load how should i load yaml in something that isnt string, or there is no other way to edit my yaml using snakeyaml? – Sirke Mar 27 '20 at 15:15
  • 1
    Since this problem is discussed quite often, I just did a [longer write-up](https://stackoverflow.com/q/60891174/347964) detailing the problems and possible solutions. Hope it helps. – flyx Mar 27 '20 at 17:32

0 Answers0