JSONmutator

A Java library for mutating JSON objects.

Лицензия

Лицензия

Категории

Категории

JSON Данные
Группа

Группа

es.us.isa
Идентификатор

Идентификатор

json-mutator
Последняя версия

Последняя версия

0.0.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

JSONmutator
A Java library for mutating JSON objects.
Ссылка на сайт

Ссылка на сайт

https://github.com/isa-group/JSONmutator
Система контроля версий

Система контроля версий

https://github.com/isa-group/JSONmutator/tree/master

Скачать json-mutator

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/es.us.isa/json-mutator/ -->
<dependency>
    <groupId>es.us.isa</groupId>
    <artifactId>json-mutator</artifactId>
    <version>0.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/es.us.isa/json-mutator/
implementation 'es.us.isa:json-mutator:0.0.1'
// https://jarcasting.com/artifacts/es.us.isa/json-mutator/
implementation ("es.us.isa:json-mutator:0.0.1")
'es.us.isa:json-mutator:jar:0.0.1'
<dependency org="es.us.isa" name="json-mutator" rev="0.0.1">
  <artifact name="json-mutator" type="jar" />
</dependency>
@Grapes(
@Grab(group='es.us.isa', module='json-mutator', version='0.0.1')
)
libraryDependencies += "es.us.isa" % "json-mutator" % "0.0.1"
[es.us.isa/json-mutator "0.0.1"]

Зависимости

compile (8)

Идентификатор библиотеки Тип Версия
com.fasterxml.jackson.core : jackson-core jar 2.9.9
com.fasterxml.jackson.core : jackson-databind jar 2.9.9
org.apache.commons : commons-lang3 jar 3.9
org.apache.commons : commons-math3 jar 3.6.1
com.google.guava : guava jar 28.0-jre
org.apache.logging.log4j : log4j-api jar 2.13.3
org.apache.logging.log4j : log4j-core jar 2.13.3
junit : junit jar 4.13

Модули Проекта

Данный проект не имеет модулей.

JSONmutator

A Java library for mutating JSON objects.

How to add a new mutation operator

For the sake of simplicity, we will explain how to add a new mutation operator with an example. This example corresponds to the addition of a String mutation operator, but it should be replicable for any other data type (integer, boolean, etc.):

Modify OperatorNames class

Create a new constant with the name of the mutation in the class OperatorNames, like this:

public class OperatorNames {
    public static final String MUTATE = "mutate";
    public static final String CHANGE_TYPE = "changeType";
    public static final String REPLACE = "replace"; // NEWLY ADDED LINE
}

Modify properties file

Add a weight to that mutation operator in the config.properties file. Note that you must use the same name for the property that you used in the constant previously defined (in this case, "replace"):

operator.value.string.weight.replace=0.1

Create MutationOperator class

Create a new class for the mutation operator under the package es.us.isa.jsonmutator.value.string0.operator. Note that this class must necessarily implement a constructor (where at least super() is called and the weight attribute is set) and the mutate method:

public class StringReplacementOperator extends AbstractOperator {

    private int minLength;      // Minimum length of the randomly generated string
    private int maxLength;      // Maximum length of the randomly generated string

    public StringReplacementOperator() {
        super();
        weight = Float.parseFloat(readProperty("operator.value.string.weight." + OperatorNames.REPLACE));
        minLength = Integer.parseInt(readProperty("operator.value.string.length.min"));
        maxLength = Integer.parseInt(readProperty("operator.value.string.length.max"));
    }

    public Object mutate(Object stringObject) {
        return RandomStringUtils.random(rand1.nextInt(minLength, maxLength), true, true);
    }
}

Modify Mutator class

Add the mutation operator to the map of operators in the constructor of the Mutator class (in this case, StringMutator):

public class StringMutator extends AbstractMutator {

    public StringMutator() {
        super();
        prob = Float.parseFloat(readProperty("operator.value.string.prob"));
        operators.put(OperatorNames.MUTATE, new StringMutationOperator());
        operators.put(OperatorNames.CHANGE_TYPE, new ChangeTypeOperator(String.class));
        operators.put(OperatorNames.REPLACE, new StringReplacementOperator()); // NEWLY ADDED LINE
    }
}
es.us.isa

ISA Group

Applied Software Engineering research group at the University of Seville

Версии библиотеки

Версия
0.0.1