MokksyJackson

Factory for creating Mokksy instances configured with Jackson as the JSON serializer.

Use this instead of Mokksy.create when tests send or receive Jackson-serialized payloads, or when typed body matchers (bodyMatchesPredicate) are used against Java POJOs.

The API mirrors Mokksy.create exactly — the same host, port, and verbose parameters — with an additional optional configureMapper callback for ObjectMapper customisation.

Requires ktor-serialization-jackson on the runtime classpath. Add it to your test dependencies:

testImplementation("io.ktor:ktor-serialization-jackson:$ktorVersion")

Basic usage (Java):

Mokksy mokksy = MokksyJackson.create().start();

mokksy.post(CreateItemRequest.class,
spec -> spec.path("/items")
.bodyMatchesPredicate(req -> "widget".equals(req.getName())))
.respondsWith(builder -> builder.body("{\"id\":\"1\"}").status(201));

Custom ObjectMapper:

Mokksy mokksy = MokksyJackson.create(ObjectMapper::findAndRegisterModules).start();

Kotlin — opt-in required:

@OptIn(ExperimentalMokksyApi::class)
val mokksy = MokksyJackson.create().start()

Functions

Link copied to clipboard
fun create(configureMapper: Consumer<ObjectMapper>): Mokksy

Creates a Mokksy instance with Jackson and a custom ObjectMapper configuration, binding to "127.0.0.1" on a random port.

fun create(host: String = DEFAULT_HOST, port: Int = 0, verbose: Boolean = false, configureMapper: Consumer<ObjectMapper> = Consumer { }): Mokksy

Creates a Mokksy instance with Jackson configured for JSON content negotiation.