Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore fields from yaml when parsing it using SnakeYaml (Unable to find property on class)

I am using SnakeYaml to parse yaml file, is there anyway to ignore properities from the yaml file ?

like image 593
Bilal Halayqa Avatar asked May 11 '15 07:05

Bilal Halayqa


People also ask

How to parse YAML file in Java?

YAML files can be parsed in a Java application using the SnakeYAML library. It is a simple, lightweight library providing high-level serialization and deserialization APIs for YAML files. To store several documents at once, use the load() or loadAll() functions in batches.

What does SnakeYAML do?

SnakeYAML allows you to read a YAML file into a simple Map object or parse the file and convert it into a custom Java object. Depending on your requirements you can decide in which format you want to read your YAML files.

Is SnakeYAML thread safe?

Since the implementation is not thread safe, different threads must have their own Yaml instance.


1 Answers

I found it :)

    Representer representer = new Representer();
    representer.getPropertyUtils().setSkipMissingProperties(true);
    
    
    Yaml yaml = new Yaml(new Constructor(MyClass.class),representer);
like image 56
Bilal Halayqa Avatar answered Sep 18 '22 15:09

Bilal Halayqa