Skip to main content

Generators Overview

DataGeneration includes 18 built-in generators for creating realistic test data.

Data Generators

Generate realistic domain-specific data:

GeneratorDescriptionExample Output
UUIDUUID v4 strings550e8400-e29b-41d4-a716-446655440000
NameNames and titlesJohn Doe, Dr., Smith
InternetEmail, URLs, domainsjohn@example.com, https://example.com
AddressAddresses and locations123 Main St, New York, 10001
CompanyCompany names and industriesAcme Corp, Technology
CountryCountries and codesUnited States, US, USD
BookBook titles, authors, genresThe Great Gatsby, F. Scott Fitzgerald
FinanceIBAN, BIC, credit cardsDE89370400440532013000, DEUTDEFF
PhonePhone numbers+1-555-123-4567

Primitive Generators

Generate basic data types:

GeneratorDescriptionOptions
NumberRandom integersmin, max
FloatFloating-point numbersmin, max, decimals
BooleanTrue/false valuesprobability
StringRandom stringslength, allowedChars, regex
DateDates and timestampsfrom, to, format

Utility Generators

Special-purpose generators:

GeneratorDescriptionUse Case
LoremLorem ipsum textPlaceholder content
SequenceAuto-incrementing numbersIDs, counters
ChoicePick from optionsEnums, statuses
CSVRead from CSV filesExternal data

Usage Patterns

Basic Generator

{
"id": {"gen": "uuid"},
"name": {"gen": "name.fullName"}
}

Generator with Options

{
"age": {"gen": "number", "min": 18, "max": 65},
"price": {"gen": "float", "min": 9.99, "max": 999.99, "decimals": 2}
}

Accessing Sub-fields

Some generators return objects with multiple fields:

{
"firstName": {"gen": "name.firstName"},
"lastName": {"gen": "name.lastName"},
"fullName": {"gen": "name.fullName"}
}

Weighted Choices

{
"priority": {
"gen": "choice",
"options": ["low", "medium", "high", "critical"],
"weights": [50, 30, 15, 5]
}
}

Custom Generators

You can create custom generators by implementing the Generator interface:

public class CustomGenerator implements Generator {
@Override
public JsonNode generate(GeneratorContext context) {
// Your generation logic
return context.mapper().valueToTree("custom value");
}
}

// Register it
DslDataGenerator.create()
.withCustomGenerator("custom", new CustomGenerator())
.fromJsonString(dsl)
.generate();

Then use it in your DSL:

{
"customField": {"gen": "custom"}
}

Generator Compatibility

Filtering Support

Only the Boolean generator currently supports filtering:

{
"isActive": {
"gen": "boolean",
"probability": 0.8,
"filter": [false] // Only generate true values
}
}

For other generators, use the Choice generator with filtering:

{
"status": {
"gen": "choice",
"options": ["active", "inactive", "banned"],
"filter": ["banned"]
}
}

Sequential Support

Generators that support sequential access:

  • Sequence - Built-in sequential behavior
  • CSV - Can read sequentially with "sequential": true
  • Choice - Can cycle through options sequentially

Next Steps