public static <T> T testSerialisation(final T object,
                                          final Class<T> clazz,
                                          final BiConsumer<ObjectMapper, String> jsonConsumer,
                                          final ObjectMapper objectMapper) {
        Objects.requireNonNull(object);
        Objects.requireNonNull(clazz);
        Objects.requireNonNull(objectMapper);

        final String json;
        try {
            json = objectMapper.writeValueAsString(object);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(LogUtil.message(
                    "Error serialising {}: {}", object, e.getMessage()), e);
        }

        LOGGER.debug(LogUtil.message("json for {}:\n{}", clazz.getSimpleName(), json));

        if (jsonConsumer != null) {
            jsonConsumer.accept(objectMapper, json);
        }

        final T object2;
        try {
            object2 = objectMapper.readValue(json, clazz);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(LogUtil.message(
                    "Error deserialising {}: {}", json, e.getMessage()), e);
        }

        Assertions.assertThat(object2)
                .isEqualTo(object);

        return object2;
    }
Does a basic serialise - de-serialise test with an equality check on the initial
and final objects. The optional jsonConsumer allows assertions to be performed
by the caller on the serialised form.

@return The de-serialised object for further inspection by the caller.
stroom-test-common/src/main/java/stroom/test/common/TestUtil.java