Last active
May 7, 2020 12:14
-
-
Save Yrwein/34dfc925ef383001efa43d4dfe1e5bec to your computer and use it in GitHub Desktop.
An example with Spring-Boot module auto-discovery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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