Properties loading - ManianVSS/Karta GitHub Wiki
Instead of using traditional Java based property files, Karta Supports standard data file formats YAML, JSON and XML to store property data. Property file paths can be configured in Karta Runtime Configuration.
A property file is a serialization of a properties store. A properties store is a map of property group to a map of property key value pairs. Property groups and keys are String and property values can be any Serializable. The de-serialization is performed using Jackson. Same property groups in multiple files will get merged and the existing mapping overridden in the order of loading the property files.
Lets assume we have a Serializable data structure as follows @Data @NoArgsConstructor @AllArgsConstructor @Builder public class ComplexDataStructure implements Serializable { private static final long serialVersionUID = 1L; private int intVal; private float floatVal; private String[] stringVal; private Date dateval; private ArrayList<ComplexDataStructure> children; }
, this can be defined in a YAML property file under a group name say "SomeStepDefinition" as follows SomeStepDefinition: complexDataStructure: intVal: 10 floatVal: 1.0 stringVal: - str1 - str2 - str3 dateval: 2020-01-01 children: - intVal: 20 floatVal: 2.0 stringVal: - str3 - str4 - str5 dateval: 2020-01-02 - intVal: 30 floatVal: 3.0 stringVal: - str6 - str7 - str9 dateval: 2020-01-03
And this property can be easily mapped in code as follows public class SomeStepDefinitions { @PropertyMapping( group = "SomeStepDefinition", value = "complexDataStructure" ) private ComplexDataStructure complexDataStructure;
Configurator class defines a properties store and provides methods to merge multiple property files and load the properties on an object. MyClass object= new MyClass();object Configurator configurator= new Configurator(); configurator.mergePropertiesFiles( "propertyfile1.yaml", "propertyfile2.json","propertyfile3.xml"); configurator.loadProperties( object);