io.dropwizard.setup.Bootstrap.getObjectMapper()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中io.dropwizard.setup.Bootstrap.getObjectMapper()方法的一些代码示例,展示了Bootstrap.getObjectMapper()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bootstrap.getObjectMapper()方法的具体详情如下:
包路径:io.dropwizard.setup.Bootstrap
类名称:Bootstrap
方法名:getObjectMapper

Bootstrap.getObjectMapper介绍

[英]Returns the bootstrap's ObjectMapper.
[中]返回引导程序的ObjectMapper。

代码示例

代码示例来源:origin: dropwizard/dropwizard

@Override
public final void initialize(Bootstrap<?> bootstrap) {
  bootstrap.getObjectMapper().registerModule(createHibernate5Module());
}

代码示例来源:origin: graphhopper/graphhopper

@Override
public void initialize(Bootstrap<?> bootstrap) {
  bootstrap.getObjectMapper().setDateFormat(new StdDateFormat());
  bootstrap.getObjectMapper().registerModule(new JtsModule());
  bootstrap.getObjectMapper().registerModule(new GraphHopperModule());
  bootstrap.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
  // Because VirtualEdgeIteratorState has getters which throw Exceptions.
  // http://stackoverflow.com/questions/35359430/how-to-make-jackson-ignore-properties-if-the-getters-throw-exceptions
  bootstrap.getObjectMapper().registerModule(new SimpleModule().setSerializerModifier(new BeanSerializerModifier() {
    @Override
    public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
      return beanProperties.stream().map(bpw -> new BeanPropertyWriter(bpw) {
        @Override
        public void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception {
          try {
            super.serializeAsField(bean, gen, prov);
          } catch (Exception e) {
            // Ignoring expected exception, see above.
          }
        }
      }).collect(Collectors.toList());
    }
  }));
}

代码示例来源:origin: graphhopper/graphhopper

@Override
public void initialize(Bootstrap<GraphHopperServerConfiguration> bootstrap) {
  bootstrap.addBundle(new GraphHopperBundle());
  bootstrap.addBundle(new ConfiguredAssetsBundle("/assets/", "/maps/", "index.html"));
  bootstrap.addCommand(new ImportCommand(bootstrap.getObjectMapper()));
}

代码示例来源:origin: dropwizard/dropwizard

@Override
@SuppressWarnings("unchecked")
public void run(Bootstrap<?> wildcardBootstrap, Namespace namespace) throws Exception {
  final Bootstrap<T> bootstrap = (Bootstrap<T>) wildcardBootstrap;
  configuration = parseConfiguration(bootstrap.getConfigurationFactoryFactory(),
                    bootstrap.getConfigurationSourceProvider(),
                    bootstrap.getValidatorFactory().getValidator(),
                    namespace.getString("file"),
                    getConfigurationClass(),
                    bootstrap.getObjectMapper());
  try {
    if (configuration != null) {
      configuration.getLoggingFactory().configure(bootstrap.getMetricRegistry(),
                            bootstrap.getApplication().getName());
    }
    run(bootstrap, namespace, configuration);
  } finally {
    if (!asynchronous) {
      cleanup();
    }
  }
}

代码示例来源:origin: dropwizard/dropwizard

@Override
protected void run(Bootstrap<T> bootstrap, Namespace namespace, T configuration) throws Exception {
  final Environment environment = new Environment(bootstrap.getApplication().getName(),
                          bootstrap.getObjectMapper(),
                          bootstrap.getValidatorFactory(),
                          bootstrap.getMetricRegistry(),
                          bootstrap.getClassLoader(),
                          bootstrap.getHealthCheckRegistry());
  configuration.getMetricsFactory().configure(environment.lifecycle(),
                        bootstrap.getMetricRegistry());
  configuration.getServerFactory().configure(environment);
  bootstrap.run(configuration, environment);
  application.run(configuration, environment);
  run(environment, namespace, configuration);
}

代码示例来源:origin: palantir/atlasdb

@Override
public void initialize(Bootstrap<TimelockBenchmarkServerConfig> bootstrap) {
  bootstrap.getObjectMapper().registerModule(new Jdk8Module());
  bootstrap.getObjectMapper().registerSubtypes(NonBlockingFileAppenderFactory.class);
  super.initialize(bootstrap);
}

代码示例来源:origin: palantir/atlasdb

@Override
public void initialize(Bootstrap<TimeLockServerConfiguration> bootstrap) {
  MetricRegistry metricRegistry = SharedMetricRegistries
      .getOrCreate("AtlasDbTest" + UUID.randomUUID().toString());
  TaggedMetricRegistry taggedMetricRegistry = new DefaultTaggedMetricRegistry();
  bootstrap.setMetricRegistry(metricRegistry);
  bootstrap.getObjectMapper().registerSubtypes(NonBlockingFileAppenderFactory.class);
  bootstrap.getObjectMapper().registerModule(new Jdk8Module());
  super.initialize(bootstrap);
}

代码示例来源:origin: palantir/atlasdb

@Override
public void initialize(Bootstrap<TimelockBenchmarkClientConfig> bootstrap) {
  MetricRegistry metricRegistry = MetricRegistries.createWithHdrHistogramReservoirs();
  bootstrap.setMetricRegistry(metricRegistry);
  bootstrap.getObjectMapper().registerModule(new Jdk8Module());
  bootstrap.getObjectMapper().registerSubtypes(NonBlockingFileAppenderFactory.class);
  super.initialize(bootstrap);
}

代码示例来源:origin: palantir/atlasdb

@Override
public void initialize(Bootstrap<AtlasDbEteConfiguration> bootstrap) {
  bootstrap.setMetricRegistry(SharedMetricRegistries.getOrCreate("AtlasDbTest"));
  enableEnvironmentVariablesInConfig(bootstrap);
  bootstrap.getObjectMapper().registerModule(new Jdk8Module());
}

代码示例来源:origin: palantir/atlasdb

@Override
public void initialize(Bootstrap<Configuration> bootstrap) {
  bootstrap.getObjectMapper().registerModule(new Jdk8Module());
}

代码示例来源:origin: HubSpot/Singularity

@Override
public void initialize(final Bootstrap<T> bootstrap) {
 if (!Strings.isNullOrEmpty(System.getProperty(SINGULARITY_DEFAULT_CONFIGURATION_PROPERTY))) {
  bootstrap.setConfigurationSourceProvider(new MergingSourceProvider(bootstrap.getConfigurationSourceProvider(), System.getProperty(SINGULARITY_DEFAULT_CONFIGURATION_PROPERTY), bootstrap.getObjectMapper(), new YAMLFactory()));
 bootstrap.getObjectMapper().registerModule(new ProtobufModule());
 bootstrap.getObjectMapper().registerModule(new GuavaModule());
 bootstrap.getObjectMapper().setSerializationInclusion(Include.NON_NULL);
 bootstrap.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

代码示例来源:origin: io.dropwizard/dropwizard-core

@Override
protected void run(Bootstrap<T> bootstrap, Namespace namespace, T configuration) throws Exception {
  final Environment environment = new Environment(bootstrap.getApplication().getName(),
                          bootstrap.getObjectMapper(),
                          bootstrap.getValidatorFactory().getValidator(),
                          bootstrap.getMetricRegistry(),
                          bootstrap.getClassLoader(),
                          bootstrap.getHealthCheckRegistry());
  configuration.getMetricsFactory().configure(environment.lifecycle(),
                        bootstrap.getMetricRegistry());
  configuration.getServerFactory().configure(environment);
  bootstrap.run(configuration, environment);
  application.run(configuration, environment);
  run(environment, namespace, configuration);
}

代码示例来源:origin: io.dropwizard/dropwizard-core

@Override
@SuppressWarnings("unchecked")
public void run(Bootstrap<?> wildcardBootstrap, Namespace namespace) throws Exception {
  final Bootstrap<T> bootstrap = (Bootstrap<T>) wildcardBootstrap;
  configuration = parseConfiguration(bootstrap.getConfigurationFactoryFactory(),
                    bootstrap.getConfigurationSourceProvider(),
                    bootstrap.getValidatorFactory().getValidator(),
                    namespace.getString("file"),
                    getConfigurationClass(),
                    bootstrap.getObjectMapper());
  try {
    if (configuration != null) {
      configuration.getLoggingFactory().configure(bootstrap.getMetricRegistry(),
                            bootstrap.getApplication().getName());
    }
    run(bootstrap, namespace, configuration);
  } finally {
    if (!asynchronous) {
      cleanup();
    }
  }
}

代码示例来源:origin: hmsonline/dropwizard-spring

@Override
public void initialize(Bootstrap<SpringServiceConfiguration> bootstrap) {
  // This is needed to avoid an exception when deserializing Json to an ArrayList<String>
  bootstrap.getObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
}

代码示例来源:origin: jvelo/mayocat-shop

@Override
public void initialize(Bootstrap<C> bootstrap)
{
  this.addModule(new AccountsModule());
  bootstrap.getObjectMapper().registerModule(new NIOModule());
  bootstrap.getObjectMapper().registerModule(new MayocatJodaModule());
  bootstrap.getObjectMapper().registerModule(new MayocatLocaleBCP47LanguageTagModule());
  bootstrap.getObjectMapper().registerModule(new TimeZoneModule());
  bootstrap.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  // TODO: remove when upgrading DW to 0.8
  bootstrap.getObjectMapper().registerModule(new PermissiveFuzzyEnumModule());
}

代码示例来源:origin: alex-shpak/rx-jersey

@Override
public void initialize(Bootstrap<RxJerseyConfiguration> bootstrap) {
  bootstrap.getObjectMapper()
      .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
  bootstrap.addBundle(new RxJerseyBundle<RxJerseyConfiguration>()
      .setClientConfigurationProvider(config -> config.client)
      .register(HeaderInterceptor.class)
  );
}

代码示例来源:origin: dropwizard/dropwizard-java8

@Override
public void initialize(final Bootstrap<?> bootstrap) {
  bootstrap.getObjectMapper().registerModules(new Jdk8Module());
  bootstrap.getObjectMapper().registerModules(new JavaTimeModule());
  final ValidatorFactory validatorFactory = Validators.newConfiguration()
      .addValidatedValueHandler(new OptionalValidatedValueUnwrapper())
      .buildValidatorFactory();
  bootstrap.setValidatorFactory(validatorFactory);
}

代码示例来源:origin: com.graphhopper/graphhopper-web

@Override
public void initialize(Bootstrap<GraphHopperServerConfiguration> bootstrap) {
  bootstrap.addBundle(new GraphHopperBundle());
  bootstrap.addBundle(new ConfiguredAssetsBundle("/assets/", "/maps/", "index.html"));
  bootstrap.addCommand(new ImportCommand(bootstrap.getObjectMapper()));
}

代码示例来源:origin: com.hubspot.dropwizard/dropwizard-guicier

@Before
public void setUp() throws Exception {
  ObjectMapper objectMapper = Jackson.newObjectMapper();
  environment = new Environment("test env", objectMapper, null, new MetricRegistry(), null);
  guiceBundle = GuiceBundle.defaultBuilder(Configuration.class)
      .modules(new TestModule())
      .build();
  Bootstrap bootstrap = mock(Bootstrap.class);
  when(bootstrap.getObjectMapper()).thenReturn(objectMapper);
  guiceBundle.initialize(bootstrap);
  guiceBundle.run(new Configuration(), environment);
}

代码示例来源:origin: bazaarvoice/emodb

@Override
public void initialize(Bootstrap<EmoConfiguration> bootstrap) {
  bootstrap.addCommand(new CreateKeyspacesCommand());
  bootstrap.addCommand(new RegisterCassandraCommand());
  bootstrap.addCommand(new ListCassandraCommand());
  bootstrap.addCommand(new UnregisterCassandraCommand());
  bootstrap.addCommand(new PurgeDatabusEventsCommand());
  bootstrap.addCommand(new AllTablesReportCommand());
  bootstrap.addCommand(new EncryptConfigurationApiKeyCommand());
  EmoServiceObjectMapperFactory.configure(bootstrap.getObjectMapper());
  bootstrap.getMetricRegistry().register("jvm.gc.totals", new EmoGarbageCollectorMetricSet());
}

相关文章