List of usage examples for com.fasterxml.jackson.databind PropertyNamingStrategy CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES
PropertyNamingStrategy CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES
To view the source code for com.fasterxml.jackson.databind PropertyNamingStrategy CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES.
Click Source Link
From source file:com.aerofs.baseline.Service.java
public final void runWithConfiguration(T configuration) throws Exception { // initialize the validation subsystem ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class).configure() .buildValidatorFactory();/*ww w.j av a 2 s .c om*/ Validator validator = validatorFactory.getValidator(); // validate the configuration Configuration.validateConfiguration(validator, configuration); // at this point we have a valid configuration // we can start logging to the correct location, // initialize common services, and start up // the jersey applications // reset the logging subsystem with the configured levels Logging.setupLogging(configuration.getLogging()); // display the server banner if it exists displayBanner(); // add a shutdown hook to release all resources cleanly Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown)); // setup some default metrics for the JVM MetricRegistries.getRegistry().register(Constants.JVM_BUFFERS, new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer())); MetricRegistries.getRegistry().register(Constants.JVM_GC, new GarbageCollectorMetricSet()); MetricRegistries.getRegistry().register(Constants.JVM_MEMORY, new MemoryUsageGaugeSet()); MetricRegistries.getRegistry().register(Constants.JVM_THREADS, new ThreadStatesGaugeSet()); // create the root service locator ServiceLocator rootLocator = ServiceLocatorFactory.getInstance().create("root"); rootLocatorReference.set(rootLocator); // grab a reference to our system-wide class loader (we'll use this for the jersey service locators) ClassLoader classLoader = rootLocator.getClass().getClassLoader(); // create the lifecycle manager LifecycleManager lifecycleManager = new LifecycleManager(rootLocator); lifecycleManagerReference.set(lifecycleManager); // after this point any services // added to the LifecycleManager will be // shut down cleanly // create and setup the system-wide Jackson object mapper ObjectMapper mapper = new ObjectMapper(); mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); // create a few singleton objects Authenticators authenticators = new Authenticators(); RegisteredCommands registeredCommands = new RegisteredCommands(); RegisteredHealthChecks registeredHealthChecks = new RegisteredHealthChecks(); // create the root environment Environment environment = new Environment(rootLocator, lifecycleManager, validator, mapper, authenticators, registeredCommands, registeredHealthChecks); // start configuring injectable objects // we'll be adding all instances and implementation classes to the root service locator // this makes them visible to the jersey applications environment.addBinder(new ConfigurationBinder<>(configuration, configuration.getClass())); environment.addBinder(new AbstractBinder() { @Override protected void configure() { bind(name).to(String.class).named(Constants.SERVICE_NAME_INJECTION_KEY); bind(validator).to(Validator.class); bind(mapper).to(ObjectMapper.class); bind(environment).to(Environment.class); bind(lifecycleManager.getScheduledExecutorService()).to(ScheduledExecutorService.class); bind(lifecycleManager.getTimer()).to(Timer.class); // FIXME (AG): use our own timer interface bind(authenticators).to(Authenticators.class); bind(registeredCommands).to(RegisteredCommands.class); bind(registeredHealthChecks).to(RegisteredHealthChecks.class); } }); // register some basic commands environment.registerCommand("gc", GarbageCollectionCommand.class); environment.registerCommand("metrics", MetricsCommand.class); environment.addAdminProvider(new AbstractBinder() { @Override protected void configure() { bind(GarbageCollectionCommand.class).to(GarbageCollectionCommand.class).in(Singleton.class); bind(MetricsCommand.class).to(MetricsCommand.class).in(Singleton.class); } }); // add exception mappers that only apply to the admin environment environment.addAdminProvider(InvalidCommandExceptionMapper.class); // add the resources we expose via the admin api environment.addAdminResource(CommandsResource.class); environment.addAdminResource(HealthCheckResource.class); // create the two environments (admin and service) String adminName = name + "-" + Constants.ADMIN_IDENTIFIER; initializeJerseyApplication(adminName, classLoader, validator, mapper, environment.getAdminResourceConfig(), configuration.getAdmin()); String serviceName = name + "-" + Constants.SERVICE_IDENTIFIER; initializeJerseyApplication(serviceName, classLoader, validator, mapper, environment.getServiceResourceConfig(), configuration.getService()); // punt to subclasses for further configuration init(configuration, environment); // after this point we can't add any more jersey providers // resources, etc. and we're ready to expose our server to the world // list the objects that are registered with the root service locator listInjected(rootLocator); // initialize the admin http server if (configuration.getAdmin().isEnabled()) { ApplicationHandler adminHandler = new ApplicationHandler(environment.getAdminResourceConfig(), null, rootLocator); listInjected(adminHandler.getServiceLocator()); HttpServer adminHttpServer = new HttpServer(Constants.ADMIN_IDENTIFIER, configuration.getAdmin(), lifecycleManager.getTimer(), adminHandler); lifecycleManager.add(adminHttpServer); } // initialize the service http server if (configuration.getService().isEnabled()) { ApplicationHandler serviceHandler = new ApplicationHandler(environment.getServiceResourceConfig(), null, rootLocator); listInjected(serviceHandler.getServiceLocator()); HttpServer serviceHttpServer = new HttpServer(Constants.SERVICE_IDENTIFIER, configuration.getService(), lifecycleManager.getTimer(), serviceHandler); lifecycleManager.add(serviceHttpServer); } // finally, start up all managed services (which includes the two servers above) lifecycleManager.start(); }
From source file:lib.Global.java
private ObjectMapper buildObjectMapper() { return new ObjectMapper().registerModules(new GuavaModule(), new JodaModule()) .setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES) .enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES) .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); }
From source file:com.nextdoor.bender.config.BenderConfig.java
public static BenderConfig load(String filename, String data) { /*/*w w w .j a v a2s. c om*/ * Configure Mapper and register polymorphic types */ ObjectMapper mapper = BenderConfig.getObjectMapper(filename); mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); /* * Optionally don't validate the config. Assume user has already * done this. */ String v = System.getenv("BENDER_SKIP_VALIDATE"); if (v != null && v.equals("true")) { return BenderConfig.load(filename, data, mapper, false); } else { return BenderConfig.load(filename, data, mapper, true); } }
From source file:org.thelq.stackexchange.api.StackClient.java
public StackClient(String seApiKey) { Preconditions.checkNotNull(seApiKey); this.seApiKey = seApiKey; this.jsonMapper = new ObjectMapper(); jsonMapper.registerModule(new JodaModule()); jsonMapper.registerModule(new GuavaModule()); jsonMapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); jsonMapper.registerModule(new SimpleModule() { @Override/*from w w w. j a v a 2s . co m*/ @SuppressWarnings("unchecked") public void setupModule(SetupContext context) { super.setupModule(context); context.addDeserializers(new Deserializers.Base() { @Override public JsonDeserializer<?> findEnumDeserializer(Class<?> type, DeserializationConfig config, BeanDescription beanDesc) throws JsonMappingException { return new UppercaseEnumDeserializer((Class<Enum<?>>) type); } }); } }); }