Checking whether yaml parser feature is enabled or not

In this post under Jackson YAML, I will show with example how to check whether a yaml parser feature is enabled or not.

In previous post under Jackson YAML, I explained the purpose of yaml parser feature “YAMLParser.Feature.PARSE_BOOLEAN_LIKE_WORDS_AS_STRINGS”.

For our example I will check whether the above parser feature is enabled or not.

Below is the complete main code

Main class

1  package package1;
2  
3  import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
4  import com.fasterxml.jackson.dataformat.yaml.YAMLParser;
5  
6  public class YAMLDemo4 {
7      public static void main(String[] args) {
8          YAMLFactory yamlFactory = new YAMLFactory();
9          boolean result = yamlFactory.isEnabled(YAMLParser.Feature.PARSE_BOOLEAN_LIKE_WORDS_AS_STRINGS);
10         System.out.println("PARSE_BOOLEAN_LIKE_WORDS_AS_STRINGS enabled or not: " + result);
11     }
12 }

In the above code, to check whether a yaml parser is enabled or not, I use “isEnabled” non-static method available in “YAMLFactory” class. Refer to line 9.

This method takes enum name as parameter and return true or false.

In this way, we can check whether a particular yaml parser feature is enabled or not.

Leave a comment