Tests the ability for your Immutables objects to be JSON friendly. Validates you have all the jackson annotations setup correctly. It can handle complex structures as well as simple ones. Allows for custom ObjectMapper to be used for the tests as well. See the state machine project for usage examples.
I've seen variations of this from different places and made my own version that uses junit5 and assertJ.
Java8 Compatible.
Library | Purpose | Version |
---|---|---|
codehead-test | Core Library |
gradle
dependencies {
testImplementation 'com.codeheadsystems:codehead-test:1.0.9'
}
@Value.Immutable
@JsonSerialize(as = ImmutableStandardImmutableModel.class)
@JsonDeserialize(builder = ImmutableStandardImmutableModel.Builder.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public interface StandardImmutableModel {
@JsonProperty("someString")
String someString();
}
public class StandardImmutableModelTest extends BaseJacksonTest<StandardImmutableModel> {
@Override
protected Class<StandardImmutableModel> getBaseClass() {
return StandardImmutableModel.class;
}
@Override
protected StandardImmutableModel getInstance() {
return ImmutableStandardImmutableModel.builder()
.someString("this string")
.build();
}
}
- Works with optional, @nullable fields.
- Compatible with @JsonIgnore.
- Handles maps/lists/sets as well.
- Jupiter and AssertJ focused.
- Polymorphic testing. Ensure your base class can marshal to your implementing one
via implementing
getPolymorphicBaseClass()