Skip to main content
Version: v1.1.x

Features

The Jackson plugin integrates Jackson with Fixture Monkey, giving you:

  • JacksonObjectArbitraryIntrospector as the default introspector — creates objects using Jackson's ObjectMapper
  • Jackson annotation support@JsonProperty, @JsonIgnore, @JsonTypeInfo, @JsonSubTypes
  • Custom ObjectMapper — use your production ObjectMapper configuration

When to use the Jackson Plugin

The Jackson plugin is a good choice when:

  • Your classes use Jackson annotations (@JsonProperty, @JsonIgnore, etc.)
  • You have a mix of Java and Kotlin classes in your project
  • Your classes don't have a no-args constructor or Lombok annotations
  • You want object creation to match your production serialization behavior
tip

If your classes have a no-args constructor with setters, the default BeanArbitraryIntrospector works fine without this plugin. For Lombok @Value classes, consider ConstructorPropertiesArbitraryIntrospector instead.

Dependencies

Gradle

testImplementation("com.navercorp.fixturemonkey:fixture-monkey-jackson:1.1.16")

Maven

<dependency>
<groupId>com.navercorp.fixturemonkey</groupId>
<artifactId>fixture-monkey-jackson</artifactId>
<version>1.1.16</version>
<scope>test</scope>
</dependency>

Plugin Setup

FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
.plugin(new JacksonPlugin())
.build();

Using a Custom ObjectMapper

If your production code uses a custom ObjectMapper, pass it to the plugin to ensure test objects match your serialization configuration:

ObjectMapper objectMapper = JsonMapper.builder()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.build();

FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
.plugin(new JacksonPlugin(objectMapper))
.build();

Quick Example

@Value
public class Product {
long id;

@JsonProperty("name")
String productName;

long price;

@JsonIgnore
List<String> options;
}

@Test
void test() {
FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
.plugin(new JacksonPlugin())
.build();

Product product = fixtureMonkey.giveMeBuilder(Product.class)
.set("name", "book") // uses @JsonProperty name
.sample();

then(product.getProductName()).isEqualTo("book");
then(product.getOptions()).isNull(); // @JsonIgnore
}

Learn More