io.dropwizard.jackson.Jackson.newMinimalObjectMapper()方法的使用及代码示例

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

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

Jackson.newMinimalObjectMapper介绍

[英]Creates a new minimal ObjectMapper that will work with Dropwizard out of box.

NOTE: Use it, if the default Dropwizard's ObjectMapper, created in #newObjectMapper(), is too aggressive for you.
[中]创建一个新的最小对象映射器,该映射器将与Dropwizard一起使用。
注意:如果在#newObjectMapper()中创建的默认Dropwizard的ObjectMapper对您来说过于激进,请使用它。

代码示例

代码示例来源: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: 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: 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: 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: 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: 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: 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: trellis-ldp/trellis

@Test
public void testGetAuthFilters() throws Exception {
  final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  config.getAuth().getJwt().setKeyStore(null);
  final List<ContainerRequestFilter> filters = TrellisUtils.getAuthFilters(config);
  assertFalse(filters.isEmpty(), "Auth filters are missing!");
  assertEquals(2L, filters.size(), "Incorrect auth filter count!");
  config.getAuth().getBasic().setEnabled(false);
  config.getAuth().getJwt().setEnabled(false);
  assertTrue(TrellisUtils.getAuthFilters(config).isEmpty(), "Auth filters should have been disabled!");
}

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

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

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

@Test
public void testConfigurationLocations() throws Exception {
  final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertEquals("/tmp/trellisData/binaries", config.getBinaries(), "Incorrect binary location!");
  assertEquals("/tmp/trellisData/mementos", config.getMementos(), "Incorrect memento location!");
  assertEquals("http://localhost:8080/", config.getBaseUrl(), "Incorrect base URL!");
  assertEquals("http://hub.example.com/", config.getHubUrl(), "Incorrect hub URL!");
  final String resources = "http://triplestore.example.com/";
  config.setResources(resources);
  assertEquals(resources, config.getResources(), "Incorrect resource location!");
}

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

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

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

@Test
public void testGetJwtAuthenticatorFederated() throws Exception {
  final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  config.getAuth().getJwt().setJwks(null);
  config.getAuth().getJwt().setKeyStore(resourceFilePath("keystore.jks"));
  config.getAuth().getJwt().setKeyIds(asList("trellis", "trellis-ec", "trellis-public"));
  assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof FederatedJwtAuthenticator,
      "JWT auth not enabled!");
}

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

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

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

@Test
  public void testConfigurationCORS1() throws Exception {
    final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
        Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
      .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertTrue(config.getCors().getEnabled(), "CORS isn't enabled!");
    assertTrue(config.getCors().getAllowOrigin().contains("*"), "CORS origin not '*'");
    assertTrue(config.getCors().getAllowHeaders().contains("Link"), "Link not in CORS allow-headers!");
    assertTrue(config.getCors().getAllowMethods().contains("PATCH"), "PATCH not in CORS allow-methods!");
    assertTrue(config.getCors().getExposeHeaders().contains("Location"), "Location not in CORS expose-headers!");
    assertEquals(180, config.getCors().getMaxAge(), "incorrect max-age in CORS headers!");
    assertTrue(config.getCors().getAllowCredentials(), "CORS allow-credentials not set!");
  }
}

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

@Test
public void testConfigurationNotifications() throws Exception {
  final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertFalse(config.getNotifications().getEnabled(), "Notifications aren't enabled!");
  assertEquals(NotificationsConfiguration.Type.NONE, config.getNotifications().getType(),
      "Incorrect notification type!");
  assertEquals("example.com:1234", config.getNotifications().getConnectionString(), "Incorrect connect string!");
  assertEquals("foo", config.getNotifications().any().get("some.other.value"), "Incorrect custom value!");
  assertEquals("test", config.getNotifications().getTopicName(), "Incorrect topic name!");
}

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

@Test
public void testConfigurationNotifications() throws Exception {
  final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertFalse(config.getNotifications().getEnabled(), "Notifications unexpectedly enabled!");
  assertEquals(NotificationsConfiguration.Type.NONE, config.getNotifications().getType(),
      "Incorrect notification type!");
  assertEquals("example.com:12345", config.getNotifications().getConnectionString(), "Incorrect connection URL!");
  assertEquals("foo", config.getNotifications().any().get("some.other.value"), "Incorrect custom property!");
  assertEquals("test-topic", config.getNotifications().getTopicName(), "Incorrect topic name!");
}

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

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

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

@Test
  public void testConfigurationCORS1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
        Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
      .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertTrue(config.getCors().getEnabled(), "CORS not enabled!");
    assertTrue(config.getCors().getAllowOrigin().contains("*"), "'*' not in CORS allow-origin!");
    assertTrue(config.getCors().getAllowHeaders().contains("Want-Digest"), "want-digest not in CORS allow-headers");
    assertTrue(config.getCors().getAllowMethods().contains("PUT"), "PUT not in CORS allow-methods!");
    assertTrue(config.getCors().getExposeHeaders().contains("Memento-Datetime"),
        "memento-datetime missing from CORS expose-headers!");
    assertEquals(180, config.getCors().getMaxAge(), "Incorrect max-age value in CORS headers!");
    assertTrue(config.getCors().getAllowCredentials(), "Incorrect allow-credentials setting in CORS headers!");
  }
}

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

@Test
public void testConfigurationAuth1() throws Exception {
  final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
      Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
    .build(new File(getClass().getResource("/config1.yml").toURI()));
  assertTrue(config.getAuth().getWebac().getEnabled(), "WebAC wasn't enabled!");
  assertEquals(100L, config.getAuth().getWebac().getCacheSize(), "Incorrect auth/webac/cacheSize value!");
  assertEquals(10L, config.getAuth().getWebac().getCacheExpireSeconds(), "Incorrect webac cache expiry!");
  assertTrue(config.getAuth().getBasic().getEnabled(), "Missing basic auth support!");
  assertEquals("users.auth", config.getAuth().getBasic().getUsersFile(), "Incorrect basic auth users file!");
  assertEquals("trellis", config.getAuth().getRealm(), "Incorrect auth realm!");
  config.getAuth().setRealm("foo");
  assertEquals("foo", config.getAuth().getRealm(), "Incorrect auth realm!");
  assertTrue(config.getAuth().getJwt().getEnabled(), "JWT not enabled!");
  assertEquals("xd1GuAwiP2+M+pyK+GlIUEAumSmFx5DP3dziGtVb1tA+/8oLXfSDMDZFkxVghyAd28rXImy18TmttUi+g0iomQ==",
      config.getAuth().getJwt().getKey(), "Incorrect JWT key!");
  assertEquals("password", config.getAuth().getJwt().getKeyStorePassword(), "Incorrect JWT keystore password!");
  assertEquals("/tmp/trellisData/keystore.jks", config.getAuth().getJwt().getKeyStore(), "Wrong keystore loc!");
  assertTrue(config.getAuth().getJwt().getKeyIds().contains("foo"), "'foo' missing from JWT key ids!");
  assertTrue(config.getAuth().getJwt().getKeyIds().contains("bar"), "'bar' missing from JWT key ids!");
  assertTrue(config.getAuth().getJwt().getKeyIds().contains("trellis"), "'trellis' missing from JWT key ids!");
  assertEquals(3, config.getAuth().getJwt().getKeyIds().size(), "Incorrect JWT Key id count!");
}

相关文章