origin-energy / java-snapshot-testing

Facebook style snapshot testing for JAVA Tests
MIT License
109 stars 15 forks source link

It should be possible to skip `findAndRegisterModules` in JacksonSnapshotSerializer #148

Closed xtermi2 closed 1 year ago

xtermi2 commented 1 year ago

Currently ObjectMapper#findAndRegisterModules is not skipable by a subclass of JacksonSnapshotSerializer. This means all Modules in the classpath which supports registering via service loader will be registered. This is not always what is needed, like in our case:

We use in our porject production code Afterburner (if JRE is <= 8) and Blackbird (if JRE is > 8). We have a switch when our ObjectMapper is configured, like this:

        if (SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_8)) {
            log.info("Use Afterburner in Java 8 environment");
            objectMapper.registerModule(new AfterburnerModule());
        } else {
            log.info("Use Blackbird in Java 9+ environment");
            objectMapper.registerModule(new BlackbirdModule());
        }

With this change a subclass of JacksonSnapshotSerializer can decide in its configure override if ObjectMapper#findAndRegisterModules should be executed (just call super) or if (like in our case) the impl should register needed modules manually (don't call super).

jackmatt2 commented 1 year ago

@xtermi2 can you run

./gradlew spotlessApply

This will format the code according to specifications.

xtermi2 commented 1 year ago

@xtermi2 can you run

./gradlew spotlessApply

This will format the code according to specifications.

Done. Sorry, haven't read carefully your contribution guide :see_no_evil: