You can create random data using trevni dependency and test scope. Here you have a sample code
import org.apache.avro.Schema;
import org.apache.trevni.avro.RandomData;
import java.util.Iterator;
public class JSONExample {
public static void main(String [] args){
Schema schema = new Schema.Parser().parse("{\n" +
" \"type\": \"record\",\n" +
" \"namespace\": \"com.acme\",\n" +
" \"name\": \"Test\",\n" +
" \"fields\": [\n" +
" { \"name\": \"name\", \"type\": \"string\" },\n" +
" { \"name\": \"age\", \"type\": \"int\" },\n" +
" { \"name\": \"sex\", \"type\": \"string\" },\n" +
" { \"name\": \"active\", \"type\": \"boolean\" }\n" +
" ]\n" +
"}");
Iterator<Object> it = new RandomData(schema, 1).iterator();
System.out.println(it.next());
}
}
output
{"name": "cjnyvbmetf", "age": -1757126879, "sex": "", "active": false}
maven dependencies
<dependencies>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>trevni-core</artifactId>
<classifier>tests</classifier>
<version>1.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>trevni-avro</artifactId>
<classifier>tests</classifier>
<version>1.8.2</version>
</dependency>
</dependencies>