Skip to content

Instantly share code, notes, and snippets.

@Yrwein
Last active May 7, 2020 12:14
Show Gist options
  • Save Yrwein/34dfc925ef383001efa43d4dfe1e5bec to your computer and use it in GitHub Desktop.
Save Yrwein/34dfc925ef383001efa43d4dfe1e5bec to your computer and use it in GitHub Desktop.
An example with Spring-Boot module auto-discovery
package com.josefczech.blog.examples.datajpatestflushandclear;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.json.JsonTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
@JsonTest
public class ModuleTest {
@TestConfiguration
static class TestConfig {
@Bean
public Module someModule() {
return new Module() {
@Override
public String getModuleName() {
return "somemodule";
}
@Override
public Version version() {
return new Version(1, 1, 1, "");
}
@Override
public void setupModule(SetupContext context) {
// TODO
}
};
}
//@Bean // uncomment to disable module auto-discovery
public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() {
return new Jackson2ObjectMapperBuilder();
}
}
@Autowired
private ObjectMapper objectMapper;
@Test
public void test() {
for (Object registeredModuleId : objectMapper.getRegisteredModuleIds()) {
System.out.println(registeredModuleId);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment