repositories {
jcenter()
}
dependencies {
compile 'be.davidopdebeeck:document-randomizer:1.0'
}
The purpose of this library is to provide an easy way to "randomize" fields in a XML or JSON document. A perfect use case would be the anonymization of production data used in development environments.
The randomizer can be configured with element mappings and element value providers.
An element mapping specifies which elements in the document will be randomized and how they will be randomized. Currently you can configure the following properties.
- xpath: specifies which elements will be selected
- unique: specifies if the new element value needs to be unique (unique in this mapping and all the other documents)
- groupNodesWithSameText: specifies if nodes with the same value are given the same new element value
- value provider: specifies how the new element value is generated
Providers define how the new element values are generated. The following providers are supplied by the library.
- RandomNumberBetweenElementValueProvider
- RandomValueElementValueProvider
- FileValuesRandomElementValueProvider
- FileValuesSequentialElementValueProvider
- CollectionRandomElementValueProvider
- CollectionSequentialElementValueProvider
<?xml version="1.0" encoding="UTF-8"?>
<root>
<name>David</name>
</root>
class Example {
public static void main(String[] args){
Randomizer randomizer = createXmlRandomizer();
randomizer.randomize(new FileInputSource(new File("path/to/xml/file.xml")))
.subscribe(System.out::println);
}
private static Randomizer createXmlRandomizer() {
return Randomizers.xmlRandomizer(
asList(new ElementValueMapping.Builder()
.withXpath("//*[local-name() = 'name']")
.withElementValueProvider(randomString(10))
.build()));
}
}
<?xml version="1.0" encoding="UTF-8"?>
<root>
<name>kofqwkshjf</name>
</root>
XML and JSON are the currently supported document languages. Feel free to contribute other document languages.