#1583 - ENH: Add type safe ServerConfig getServiceObject(Class<P> cls) and putServiceObject()

This commit is contained in:
rob bygrave
2018-12-19 21:14:25 +13:00
parent ced8c79458
commit 049cacad1c
2 changed files with 58 additions and 0 deletions
@@ -1,5 +1,6 @@
package io.ebean.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.ebean.annotation.PersistBatch;
import io.ebean.config.dbplatform.IdType;
import io.ebean.datasource.DataSourceConfig;
@@ -121,4 +122,19 @@ public class ServerConfigTest {
serverConfig.setIdGeneratorAutomatic(false);
assertFalse(serverConfig.isIdGeneratorAutomatic());
}
@Test
public void test_putServiceObject() {
ObjectMapper objectMapper = new ObjectMapper();
ServerConfig config = new ServerConfig();
config.putServiceObject(objectMapper);
ObjectMapper mapper0 = config.getServiceObject(ObjectMapper.class);
ObjectMapper mapper1 = (ObjectMapper)config.getServiceObject("objectMapper");
assertThat(objectMapper).isSameAs(mapper0);
assertThat(objectMapper).isSameAs(mapper1);
}
}