parameter.setContext(splitName[0]); // value = dev
parameter.setRegion(splitName[1]); // value = asia
parameter.setLob(splitName[2]); // value = all
So this is a small piece of java code and i'm assigning some values in it as you can see. Bascially i'm writing a yaml file by reading some text file.
context: dev
region: asia
lob: all
This is Yaml file that is converted using snakeYaml Library, so my problem is i want double quotes in values eg:- "dev".
context: "dev"
region: "asia"
lob: "all"
I want the format above but I'm not able to find out how would i be able to achieve that.Please help!!
What would i have to do to add double quotes in values area in key-value pair of yaml.
Edit:
parameter.setContext("\"" splitName[0] "\"");
parameter.setRegion("\"" splitName[1] "\"");
parameter.setLob("\"" splitName[2] "\"");
And if I am doing this for double quotes the output coming is like below:
context: '"dev"'
region: '"asia"'
lob: '"all"'
CodePudding user response:
According to the yaml spec you can use a backslash to escape a double quote.
solution: "a double quote written like \" should work"
CodePudding user response:
What are you using for serialising your object before writing to the file. I know jackson have a MINIMIZE_QUOTES which is by default enabled and quotes should be present. You can check in document here if that is the case: https://fasterxml.github.io/jackson-dataformats-text/javadoc/yaml/2.9/com/fasterxml/jackson/dataformat/yaml/YAMLGenerator.Feature.html