io.dropwizard.jackson.Jackson类的使用及代码示例

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

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

Jackson介绍

[英]A utility class for Jackson.
[中]Jackson的实用程序类。

代码示例

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

@SuppressWarnings("unchecked")
public POJOConfigurationFactory(C cfg) {
  super((Class<C>) cfg.getClass(), null, Jackson.newObjectMapper(), "dw");
  configuration = cfg;
}

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

/**
 * Creates a new {@link ObjectMapper} with Guava, Logback, and Joda Time support, as well as
 * support for {@link JsonSnakeCase}. Also includes all {@link Discoverable} interface implementations.
 */
public static ObjectMapper newObjectMapper() {
  final ObjectMapper mapper = new ObjectMapper();
  return configure(mapper);
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testConfigurationNamespaces1() throws Exception {
  final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertEquals("/tmp/trellisData/namespaces.json", config.getNamespaces(), "Incorrect namespace location!");
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testGetCORSConfig() throws Exception {
  final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertTrue(TrellisUtils.getCorsConfiguration(config).isPresent(), "CORS configuration is missing!");
  config.getCors().setEnabled(false);
  assertFalse(TrellisUtils.getCorsConfiguration(config).isPresent(), "CORS config persists after disabling it!");
}

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

/**
 * Creates a new {@link Bootstrap} for the given application.
 *
 * @param application a Dropwizard {@link Application}
 */
public Bootstrap(Application<T> application) {
  this.application = application;
  this.objectMapper = Jackson.newObjectMapper();
  this.configuredBundles = new ArrayList<>();
  this.commands = new ArrayList<>();
  this.validatorFactory = Validators.newValidatorFactory();
  this.metricRegistry = new MetricRegistry();
  this.configurationSourceProvider = new FileConfigurationSourceProvider();
  this.classLoader = Thread.currentThread().getContextClassLoader();
  this.configurationFactoryFactory = new DefaultConfigurationFactoryFactory<>();
  this.healthCheckRegistry = new HealthCheckRegistry();
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testGetJwksAuthenticator() throws Exception {
  final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof JwksAuthenticator,
      "JWT auth not enabled!");
}

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

/**
 * Creates a new {@link ObjectMapper} with a custom {@link com.fasterxml.jackson.core.JsonFactory}
 * with Guava, Logback, and Joda Time support, as well as support for {@link JsonSnakeCase}.
 * Also includes all {@link Discoverable} interface implementations.
 *
 * @param jsonFactory instance of {@link com.fasterxml.jackson.core.JsonFactory} to use
 *                    for the created {@link com.fasterxml.jackson.databind.ObjectMapper} instance.
 */
public static ObjectMapper newObjectMapper(@Nullable JsonFactory jsonFactory) {
  final ObjectMapper mapper = new ObjectMapper(jsonFactory);
  return configure(mapper);
}

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

protected JsonFormatter createDropwizardJsonFormatter() {
  return new JsonFormatter(Jackson.newObjectMapper(), isPrettyPrint(), isAppendLineSeparator());
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testConfigurationLocations() throws Exception {
  final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertEquals("http://localhost:8080/", config.getBaseUrl(), "Incorrect baseUrl!");
  assertEquals("http://hub.example.com/", config.getHubUrl(), "Incorrect hubUrl!");
}

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

/**
 * Creates a new {@link ObjectMapper} with Guava, Logback, and Joda Time support, as well as
 * support for {@link JsonSnakeCase}. Also includes all {@link Discoverable} interface implementations.
 */
public static ObjectMapper newObjectMapper() {
  final ObjectMapper mapper = new ObjectMapper();
  return configure(mapper);
}

代码示例来源:origin: spotify/helios

protected static Environment createEnvironment(final String name) {
 final Validator validator = Validation
   .byProvider(HibernateValidator.class)
   .configure()
   .addValidatedValueHandler(new OptionalValidatedValueUnwrapper())
   .buildValidatorFactory()
   .getValidator();
 return new Environment(name,
   Jackson.newObjectMapper(),
   validator,
   new MetricRegistry(),
   Thread.currentThread().getContextClassLoader());
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testGetWebacCache() throws Exception {
  final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertTrue(TrellisUtils.getWebacCache(config).isPresent(), "WebAC configuration not present!");
  config.getAuth().getWebac().setEnabled(false);
  assertFalse(TrellisUtils.getWebacCache(config).isPresent(), "WebAC config persists after disabling it!");
}

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

/**
 * Creates a new {@link ObjectMapper} with a custom {@link com.fasterxml.jackson.core.JsonFactory}
 * with Guava, Logback, and Joda Time support, as well as support for {@link JsonSnakeCase}.
 * Also includes all {@link Discoverable} interface implementations.
 *
 * @param jsonFactory instance of {@link com.fasterxml.jackson.core.JsonFactory} to use
 *                    for the created {@link com.fasterxml.jackson.databind.ObjectMapper} instance.
 */
public static ObjectMapper newObjectMapper(@Nullable JsonFactory jsonFactory) {
  final ObjectMapper mapper = new ObjectMapper(jsonFactory);
  return configure(mapper);
}

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

configuration = Jackson.newObjectMapper().treeToValue(jsonNode, LoggerConfiguration.class);
} catch (JsonProcessingException e) {
  throw new IllegalArgumentException("Wrong format of logger '" + entry.getKey() + "'", e);

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testConfigurationAssets1() throws Exception {
  final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertEquals("org/trellisldp/rdfa/resource.mustache", config.getAssets().getTemplate(), "Bad assets/template");
  assertEquals("http://example.com/image.icon", config.getAssets().getIcon(), "Bad assets/icon value!");
  assertTrue(config.getAssets().getJs().contains("http://example.com/scripts1.js"), "Missing assets/js value!");
  assertTrue(config.getAssets().getCss().contains("http://example.com/styles1.css"), "Missing assets/css value!");
}

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

/**
 * Creates a new {@link Bootstrap} for the given application.
 *
 * @param application a Dropwizard {@link Application}
 */
public Bootstrap(Application<T> application) {
  this.application = application;
  this.objectMapper = Jackson.newObjectMapper();
  this.bundles = new ArrayList<>();
  this.configuredBundles = new ArrayList<>();
  this.commands = new ArrayList<>();
  this.validatorFactory = Validators.newValidatorFactory();
  this.metricRegistry = new MetricRegistry();
  this.configurationSourceProvider = new FileConfigurationSourceProvider();
  this.classLoader = Thread.currentThread().getContextClassLoader();
  this.configurationFactoryFactory = new DefaultConfigurationFactoryFactory<>();
  this.healthCheckRegistry = new HealthCheckRegistry();
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testGetJwtAuthenticatorNoKeystore() throws Exception {
  final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  final String nonexistent = resourceFilePath("config1.yml").replaceAll("config1.yml", "nonexistent.yml");
  config.getAuth().getJwt().setJwks(null);
  config.getAuth().getJwt().setKeyStore(nonexistent);
  assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof JwtAuthenticator,
      "JWT auth not disabled!");
}

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

@Test
public void testSingularityTaskIdSerialization() throws Exception {
 ObjectMapper om = Jackson.newObjectMapper()
   .setSerializationInclusion(Include.NON_NULL)
   .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
   .registerModule(new ProtobufModule());
 SingularityTaskId taskId = new SingularityTaskId("rid", "did", 100, 1, "host", "rack");
 String id = taskId.getId();
 SingularityTaskId fromId = SingularityTaskId.valueOf(id);
 SingularityTaskId fromJson = om.readValue(om.writeValueAsBytes(taskId), SingularityTaskId.class);
 assertEquals(taskId, fromId);
 assertEquals(taskId, fromJson);
 assertEquals(fromId, fromJson);
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testConfigurationAssets1() throws Exception {
  final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertEquals("org/trellisldp/rdfa/resource.mustache", config.getAssets().getTemplate(), "Incorrect asset tpl!");
  assertEquals("http://example.org/image.icon", config.getAssets().getIcon(), "Incorrect asset icon!");
  assertTrue(config.getAssets().getJs().contains("http://example.org/scripts1.js"), "Incorrect asset js!");
  assertTrue(config.getAssets().getCss().contains("http://example.org/styles1.css"), "Incorrect asset css!");
}

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

@SuppressWarnings("unchecked")
public POJOConfigurationFactory(C cfg) {
  super((Class<C>) cfg.getClass(), null, Jackson.newObjectMapper(), "dw");
  configuration = cfg;
}

相关文章

微信公众号

最新文章

更多