# Datafaker replaces java-faker's Java 8 floor with Java 17 and an expression language

> Datafaker is the maintained fork of java-faker for the JVM, generating names, addresses and every other provider from Java, Kotlin, Groovy or JShell. It adds an expression syntax with interpolation, collection and stream builders, and schema-driven CSV and JSON output, and it requires Java 17 on the 2.x line.

**datafaker-net/datafaker** — Generating fake data for the JVM (Java, Kotlin, Groovy) has never been easier!

- Repository: https://github.com/datafaker-net/datafaker
- Website: https://www.datafaker.net
- Stars: 1,808 · Forks: 250
- Language: Java
- License: Apache-2.0
- Published: 2026-10-16 · Updated: 2026-10-16 · Language: en
- Canonical page: https://hysenlabs.com/projects/datafaker-net-datafaker

## The fork exists because the Java baseline moved

Datafaker describes itself as a modern fork of java-faker, carrying up-to-date libraries and several newly added fake generators. The README is explicit about the version split: Datafaker 2.x has Java 17 as the minimum requirement, and if Java 17 is not an option, 1.x is the alternative, which is built on Java 8 but no longer maintained.

Datafaker 2.x raised its minimum requirement to Java 17, while Datafaker 1.x remains available for older projects but is no longer maintained.

The lineage matters for adoption because it explains the API shape. Providers are reached through a fluent entry point, `new Faker()`, then a method per data type:

```java
Faker faker = new Faker();

String name = faker.name().fullName();
String firstName = faker.name().firstName();
String lastName = faker.name().lastName();

String streetAddress = faker.address().streetAddress();
```

Anyone who has used java-faker, Ruby faker, Python faker, PHP faker, Perl Data::Faker or Faker.js will recognise the model. The README lists those projects as its peers, which tells you both what it is competing with and how portable the mental model is across languages.

The stated purpose is narrow and honest: getting pretty data for a showcase while developing a new project. It is not positioned as a load testing tool or a database seeding framework, though the API does not stop you using it for either.

## The expression API is where the fork added real capability

A notable Datafaker capability is `faker.expression()`, which mixes generator calls with string transformation in one string.

```java
faker.expression("#{letterify 'test????test'}"); // testqwastest
faker.expression("#{numerify '#test#'}"); // 3test5
faker.expression("#{templatify 'test','t','q','@'}"); // @esq
faker.expression("#{regexify '[a-z]{4,10}'}"); // wbevoa
```

`letterify` replaces question marks, `numerify` replaces hashes with digits, `templatify` substitutes characters positionally, and `regexify` generates a string matching a pattern. That last one is the useful one for test fixtures: you can assert that a generated identifier matches a shape without writing the generator for it.

The language composes. `options.option '23','2','5','$','%','*'` picks one value from a list, and the resulting `*` shows why you would want it: generating punctuation-laden input for a parser test.

The nested cases are where it earns its keep, since the expression body can itself contain expressions. The `csv` form builds a header plus rows using other generators, and the `json` form nests a JSON object structure with a generator call at each leaf:

```java
faker.expression("#{json 'person','#{json ''first_name'',''#{Name.first_name}'',''last_name'',''#{Name.last_name}''}','address','#{json ''country'',''#{Address.country}'',''city'',''#{Address.city}''}'}");
```

which produces a JSON document with a person object and an address object. Note the doubled quotes inside, which is Java string escaping colliding with the expression parser's own quoting. That is a real ergonomic cost, and it is why the csv and json forms are documented separately with more examples at the project's expressions documentation page.

## Collections and streams split on whether you want bounded or endless data

Generating a list of fake records is a builder with an explicit length:

```java
List<String> names = faker.collection(
                          () -> faker.name().firstName(),
                          () -> faker.name().lastName())
                     .len(3, 5)
                     .generate();
```

`len(3, 5)` takes a range, and the README's output shows four elements, so it is a random count in that interval rather than the endpoints. There is also `maxLen` in use elsewhere in the documentation. The suppliers passed in are alternated, so the result is a flat interleaved list rather than a list of pairs.

The stream form is the same suppliers with no bound:

```java
Stream<String> names = faker.stream(
                          () -> faker.name().firstName(),
                          () -> faker.name().lastName())
                     .generate();
```

The README describes this as generating an infinite stream. That is useful when combined with `limit`, and it is a trap if you forget: an unbounded stream passed straight into a loop will run until memory is gone. Worth knowing before you copy the snippet.

A third variant appears in the transformation examples, `faker.collection(faker::name)`, passing a method reference for a whole provider. That is the compact form when you want a list of person objects rather than a list of strings.

Both builders are about volume shaping, which is the part most fake data libraries leave to you. Being able to say 'between 3 and 5 rows' rather than looping yourself is a small thing that removes a loop from every fixture.

## Schema separates generating data from reshaping data you already have

The formats layer handles structured generation and transformation. It handles two situations the README names explicitly: generating from scratch, and taking a sequence of objects you already have and extracting values from them into a specific format.

Both need a `Schema`, which describes fields and a way of generating them. The difference is what fills each field. Generation from scratch uses `Suppliers`; transformation uses `Functions` such as `Name::firstName`.

The CSV path shows both side by side:

```java
CsvTransformer<Name> transformer =
        CsvTransformer.<Name>builder().header(true).separator(",").build();

Schema<Name, String> fromScratch =
    Schema.of(field("firstName", () -> faker.name().firstName()),
        field("lastname", () -> faker.name().lastName()));
```

The transformer itself is shared, so the same formatting settings apply whether the values are invented or extracted. `header(true)` and the separator are builder options, and the README prints a header row of quoted column names followed by data rows.

This is worth understanding as a general pattern rather than a CSV detail. A `Schema` plus a `Transformer` is a projection system: you declare fields once and choose whether the values come from suppliers or accessors. The README mentions two ways of data generation in specific formats, and JSON is the other one, with JShell examples showing the same import list for `Schema`, `CsvTransformer` and the static `Field.field`.

For a test that needs realistic-looking CSV fixtures, or for converting an existing object list into a fixture file, that is a real saving.

## Trying it needs no project, thanks to JBang

The fastest way to evaluate the library is JShell, and the README gives two ways in.

From a project root, using whatever jar the build produced:

```bash
jshell --class-path $(ls -d target/*.jar | tr '\n' ':')
```

Or anywhere, with no project and no download, using JBang:

```bash
jbang -i net.datafaker:datafaker:2.7.0
```

The second is the better one for evaluating a library, because it resolves the artifact from Maven Central on the spot. The transcript in the README shows the resulting REPL and two calls, `faker.address().city()` returning a string like Brittneymouth and `faker.name().fullName()` returning something like Vernie Schmidt.

For a real project, the dependency coordinates are:

```xml
<dependency>
    <groupId>net.datafaker</groupId>
    <artifactId>datafaker</artifactId>
    <version>2.7.0</version>
</dependency>
```

and Gradle users take `implementation 'net.datafaker:datafaker:2.7.0'`.

Note the version strategy. Releases are on Maven Central, and a `3.0.0-SNAPSHOT` is published automatically after every push to main, downloadable from the Sonatype snapshot repository at `https://central.sonatype.com/repository/maven-snapshots/`. That is convenient for following development, and it is not something to put in a build that needs to be reproducible.

## Actively developed, Apache-2.0, and honest about the 1.x line

The repository is not archived and the last push was on 2026-10-14. Releases are frequent: 2.7.0 on 2026-06-24, 2.6.0 on 2026-06-17, 2.5.4 on 2026-02-11.

The 1.x situation is stated without hedging: built on Java 8, no longer maintained, and users are recommended to upgrade to 2.x. That is the correct thing to say, and it is also the decision point. A project on Java 11 can use the unmaintained 1.x line, but it must upgrade its runtime before adopting 2.x.

Licensing is Apache-2.0, which is permissive and includes a patent grant. For test fixtures that end up in a proprietary repository, that removes a question you would otherwise have.

The repository layout is a standard Maven build with a wrapper (`mvnw`, `mvnw.cmd`), a `.mvn/` directory and a `.java-version` file, plus documentation built with MkDocs from `docs/` and `mkdocs.yml` given their own `requirements-docs.txt`. `renovate.json` shows dependency updates are automated, `RELEASE_PROCESS.md` documents how releases are cut, and `FIRST_TIME_CONTRIBUTOR.md` exists alongside `CONTRIBUTING.md` and `CODE_OF_CONDUCT.md`. A `NOTES.md` at the root and a `scripts/` directory suggest some working notes or local tooling.

Coverage is tracked with codecov, which is the only quality signal in the README badges and is the one worth watching for a testing library.

## Conclusion

Adopt Datafaker when your JVM project needs deterministic-looking sample data for tests, demos or a local database, and you are on Java 17 or later. Do not adopt the 2.x line for a Java 8 or 11 build, since 1.x is the only option there and the README states 1.x is no longer maintained. Verify first whether your values must be stable across runs, because a bare new Faker() with no seed gives different data each time, and confirm whether your build resolves the snapshot version 3.0.0-SNAPSHOT from the Sonatype snapshot repository rather than pinning 2.7.0.

## FAQ

### What Java version does Datafaker require?

Datafaker 2.x requires Java 17 as the minimum. Datafaker 1.x is built on Java 8 for projects that cannot move, but the README states 1.x is no longer maintained and recommends upgrading to 2.x.

### How do I add Datafaker to a Maven project?

Add the net.datafaker:datafaker dependency with the version you want, 2.7.0 in the README example. Gradle users add `implementation 'net.datafaker:datafaker:2.7.0'` instead.

### What is the difference between java-faker and Datafaker?

Datafaker is a modern fork of java-faker with up-to-date libraries and several newly added fake generators. It raised the minimum to Java 17 on the 2.x line and adds the expression API, collection and stream builders, and schema-driven formatting.

### Can I try Datafaker without setting up a project?

Yes. The README shows running `jbang -i net.datafaker:datafaker:2.7.0`, which resolves the artifact and opens JShell with no project root or download step. From a project root you can also use `jshell --class-path $(ls -d target/*.jar | tr '\n' ':')`.

### How do I generate a matching random string in Datafaker?

Use the expression API with the regexify generator, for example `faker.expression("#{regexify '[a-z]{4,10}'}")`. The library also offers letterify, numerify, templatify, options.option and a csv form that interpolates other generators.

### Does Datafaker work with Kotlin?

Yes. The README gives a Kotlin example using `Faker()` with the same provider calls as Java, and the library targets the JVM generally including Java, Kotlin and Groovy.

## Sources

- [datafaker-net/datafaker on GitHub](https://github.com/datafaker-net/datafaker)
- [License: Apache-2.0](https://github.com/datafaker-net/datafaker/blob/main/LICENSE)
- [Project website](https://www.datafaker.net)
- [README](https://github.com/datafaker-net/datafaker/blob/main/README.md)
- [Releases](https://github.com/datafaker-net/datafaker/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/datafaker-net-datafaker
