'How to create class in java to create pipe character in yaml file

I have to create a YAML file with data in the following format

nlu:
- intent: greet
  examples: |
    - hey
    - hello
    - hi
    - hello there
    

I have a class in java as

public class Nlu {
    private List<Intent> nlu;
}

class Intent{
  String intent;
  List<String> examples;
}

My code is

ObjectMapper om = new ObjectMapper(new YAMLFactory().enable(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS)
        .enable(YAMLGenerator.Feature.MINIMIZE_QUOTES));
        om.setVisibility(om.getVisibilityChecker()
                .withFieldVisibility(JsonAutoDetect.Visibility.ANY));
        om.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        om.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);

Intent intent = new Intent().intent("inform")
                .examples(examples);
        Nlu nlu = new Nlu();
        nlu.setNlu(new ArrayList<>());
        nlu.getNlu().add(intent);

        om.writeValue(new File("person2.yaml"), nlu);
}

However, my output is

nlu:
- intent: greet
  examples:
  - hey
  - hello
  - hi
  - hello there

I can't see the pipe character. How can I figure the class nlu, Intent object to get a response as I am expecting.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source