Read data from YAML and Json using Java
Aug 16, 2022
In the automation frameworks whether its TestNG/Cucumber based we need to get Test data in order to parameterise.
Here is the simple ways to read data from YAML and Json using Jackson lib in Java.
Use the following libraries :
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.3.0</version>
</dependency>
Check out the following code where tries to read ‘Students.json’/’Students.YAML’ using Object Mapper.
Hope this helps. :)