當前位置: 首頁>>代碼示例>>Java>>正文


Java Jackson類代碼示例

本文整理匯總了Java中io.dropwizard.jackson.Jackson的典型用法代碼示例。如果您正苦於以下問題:Java Jackson類的具體用法?Java Jackson怎麽用?Java Jackson使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Jackson類屬於io.dropwizard.jackson包,在下文中一共展示了Jackson類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSerialization

import io.dropwizard.jackson.Jackson; //導入依賴的package包/類
@Test
public void testSerialization() throws IOException {
  final String json =
    "{" +
      "\"type\": \"tcp\"," +
      "\"host\": \"i am a host\"," +
      "\"port\": \"12345\"," +
      "\"timeout\": \"5 minutes\"" +
    "}";

  final ObjectMapper mapper = Jackson.newObjectMapper();
  mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));

  final Environment env = mock(Environment.class);
  when(env.getObjectMapper()).thenReturn(mapper);

  final InfluxDbTcpWriter.Factory factory = mapper.readValue(json, InfluxDbTcpWriter.Factory.class);
  assertEquals("expected TCP host", "i am a host", factory.host());
  assertEquals("expected TCP port", 12345, factory.port());
  assertEquals("expected TCP timeout", Duration.minutes(5), factory.timeout());
}
 
開發者ID:kickstarter,項目名稱:dropwizard-influxdb-reporter,代碼行數:22,代碼來源:InfluxDbTcpWriterTest.java

示例2: testGetAuthFilters

import io.dropwizard.jackson.Jackson; //導入依賴的package包/類
@Test
public void testGetAuthFilters() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    final Optional<List<AuthFilter>> filters = TrellisUtils.getAuthFilters(config);
    assertTrue(filters.isPresent());
    filters.ifPresent(f -> assertEquals(3L, f.size()));

    config.getAuth().getAnon().setEnabled(false);
    config.getAuth().getBasic().setEnabled(false);
    config.getAuth().getJwt().setEnabled(false);

    assertFalse(TrellisUtils.getAuthFilters(config).isPresent());
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:17,代碼來源:TrellisUtilsTest.java

示例3: testConfigurationAuth1

import io.dropwizard.jackson.Jackson; //導入依賴的package包/類
@Test
public void testConfigurationAuth1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertTrue(config.getAuth().getWebac().getEnabled());
    assertEquals((Long) 100L, config.getAuth().getWebac().getCacheSize());
    assertEquals((Long) 10L, config.getAuth().getWebac().getCacheExpireSeconds());
    assertTrue(config.getAuth().getAnon().getEnabled());
    assertTrue(config.getAuth().getBasic().getEnabled());
    assertEquals("users.auth", config.getAuth().getBasic().getUsersFile());
    assertTrue(config.getAuth().getJwt().getEnabled());
    assertEquals("secret", config.getAuth().getJwt().getKey());
    assertFalse(config.getAuth().getJwt().getBase64Encoded());
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:17,代碼來源:TrellisConfigurationTest.java

示例4: testSingularityTaskIdSerialization

import io.dropwizard.jackson.Jackson; //導入依賴的package包/類
@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);
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:17,代碼來源:JavaUtilsTest.java

示例5: getConfiguration

import io.dropwizard.jackson.Jackson; //導入依賴的package包/類
@Override
public RestlerConfig getConfiguration()  {
    ObjectMapper objectMapper = Jackson.newObjectMapper();

    ValidatorFactory validatorFactory = Validation
            .byProvider(HibernateValidator.class)
            .configure()
            .addValidatedValueHandler(new OptionalValidatedValueUnwrapper())
            .buildValidatorFactory();


    final ConfigurationFactory<RestlerConfig> configurationFactory =
            new DefaultConfigurationFactoryFactory<RestlerConfig>().create(RestlerConfig.class, validatorFactory.getValidator(), objectMapper, "dw");

    try {
        return configurationFactory.build(new FileConfigurationSourceProvider(), TEST_CONFIG_FILE);
    } catch (Exception e) {
        throw new RuntimeException("Cannot get test configuration", e);
    }
}
 
開發者ID:researchgate,項目名稱:restler,代碼行數:21,代碼來源:TestRestlerModule.java

示例6: getRecordByKey

import io.dropwizard.jackson.Jackson; //導入依賴的package包/類
@Test
public void getRecordByKey() throws JSONException, IOException {
    Response response = register.getRequest(address, "/record/6789.json");

    assertThat(response.getStatus(), equalTo(200));

    assertThat(response.getHeaderString("Link"), equalTo("</record/6789/entries>; rel=\"version-history\""));

    JsonNode res = Jackson.newObjectMapper().readValue(response.readEntity(String.class), JsonNode.class).get("6789");
    assertThat(res.get("entry-number").textValue(), equalTo("2"));
    assertThat(res.get("key").textValue(), equalTo("6789"));
    assertTrue(res.get("entry-timestamp").textValue().matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"));

    ArrayNode items = (ArrayNode)res.get("item");
    assertThat(items.size(), is(1));
    JsonNode itemMap = items.get(0);
    assertThat(itemMap.get("street").asText(), is("presley"));
    assertThat(itemMap.get("address").asText(), is("6789"));
}
 
開發者ID:openregister,項目名稱:openregister-java,代碼行數:20,代碼來源:RecordResourceFunctionalTest.java

示例7: getRecords

import io.dropwizard.jackson.Jackson; //導入依賴的package包/類
@Test
public void getRecords() throws IOException {
    Response response = register.getRequest(address, "/records.json");
    
    assertThat(response.getStatus(), equalTo(200));

    JsonNode res = Jackson.newObjectMapper().readValue(response.readEntity(String.class), JsonNode.class);

    JsonNode firstRecord = res.get("145678");
    assertThat(firstRecord.get("entry-number").textValue(), equalTo("3"));
    assertThat(firstRecord.get("index-entry-number").textValue(), equalTo("3"));
    assertTrue(firstRecord.get("entry-timestamp").textValue().matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"));
    assertThat(firstRecord.get("item").size(), equalTo(1));

    JsonNode secondRecord = res.get("6789");
    assertThat(secondRecord.get("entry-number").textValue(), equalTo("2"));
    assertThat(secondRecord.get("index-entry-number").textValue(), equalTo("2"));
    assertTrue(secondRecord.get("entry-timestamp").textValue().matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"));
    assertThat(secondRecord.get("item").size(), equalTo(1));
}
 
開發者ID:openregister,項目名稱:openregister-java,代碼行數:21,代碼來源:RecordResourceFunctionalTest.java

示例8: historyResource_returnsHistoryOfARecord

import io.dropwizard.jackson.Jackson; //導入依賴的package包/類
@Test
public void historyResource_returnsHistoryOfARecord() throws IOException {
    Response response = register.getRequest(address, "/record/6789/entries.json");

    assertThat(response.getStatus(), equalTo(200));

    JsonNode res = Jackson.newObjectMapper().readValue(response.readEntity(String.class), JsonNode.class);

    assertThat(res.isArray(), equalTo(true));

    JsonNode firstEntry = res.get(0);
    assertThat(firstEntry.get("index-entry-number").textValue(), equalTo("1"));
    assertThat(firstEntry.get("entry-number").textValue(), equalTo("1"));
    assertThat(firstEntry.get("item-hash").get(0).textValue(), equalTo("sha-256:9432331d3343a7ceaaee46308069d01836460294c672223b236727a790acf786" ));
    assertTrue(firstEntry.get("entry-timestamp").textValue().matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"));

    JsonNode secondEntry = res.get(1);
    assertThat(secondEntry.get("index-entry-number").textValue(), equalTo("2"));
    assertThat(secondEntry.get("entry-number").textValue(), equalTo("2"));
    assertThat(secondEntry.get("item-hash").get(0).textValue(), equalTo("sha-256:bd239db51960376826b937a615f0f3397485f00611d35bb7e951e357bf73b934" ));
    assertTrue(secondEntry.get("entry-timestamp").textValue().matches("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"));
}
 
開發者ID:openregister,項目名稱:openregister-java,代碼行數:23,代碼來源:RecordResourceFunctionalTest.java

示例9: getRecordsView

import io.dropwizard.jackson.Jackson; //導入依賴的package包/類
private RecordsView getRecordsView() throws IOException, JSONException {
    final ObjectMapper objectMapper = Jackson.newObjectMapper();
    final Instant t1 = Instant.parse("2016-03-29T08:59:25Z");
    final Instant t2 = Instant.parse("2016-03-28T09:49:26Z");
    final Entry entry1 = new Entry(1, new HashValue(HashingAlgorithm.SHA256, "ab"), t1, "123", EntryType.user);
    final Entry entry2 = new Entry(2, new HashValue(HashingAlgorithm.SHA256, "cd"), t2, "456", EntryType.user);
    final Item item1 = new Item(new HashValue(HashingAlgorithm.SHA256, "ab"), objectMapper.readTree("{\"address\":\"123\",\"street\":\"foo\"}"));
    final Item item2 = new Item(new HashValue(HashingAlgorithm.SHA256, "cd"), objectMapper.readTree("{\"address\":\"456\",\"street\":\"bar\"}"));
    final Record record1 = new Record(entry1, Collections.singletonList(item1));
    final Record record2 = new Record(entry2, Collections.singletonList(item2));
    final ItemConverter itemConverter = mock(ItemConverter.class);
    final Map<String, Field> fieldsByName = mock(Map.class);

    when(itemConverter.convertItem(item1, fieldsByName)).thenReturn(ImmutableMap.of("address", new StringValue("123"),
            "street", new StringValue("foo")));
    when(itemConverter.convertItem(item2, fieldsByName)).thenReturn(ImmutableMap.of("address", new StringValue("456"),
            "street", new StringValue("bar")));

    return new RecordsView(Arrays.asList(record1, record2), fieldsByName, itemConverter, false, false);
}
 
開發者ID:openregister,項目名稱:openregister-java,代碼行數:21,代碼來源:PreviewRecordPageViewTest.java

示例10: beforeAll

import io.dropwizard.jackson.Jackson; //導入依賴的package包/類
@Before
public void beforeAll() throws Exception {
    server = new TestingServer();
    server.start();
    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    when(mockCapabilities.supportsNamedVips()).thenReturn(true);
    taskFactory = new CassandraDaemonTask.Factory(mockCapabilities);
    configurationFactory = new ConfigurationFactory<>(
                    MutableSchedulerConfiguration.class,
                    BaseValidator.newValidator(),
                    Jackson.newObjectMapper()
                            .registerModule(new GuavaModule())
                            .registerModule(new Jdk8Module()),
                    "dw");
    connectString = server.getConnectString();
}
 
開發者ID:mesosphere,項目名稱:dcos-cassandra-service,代碼行數:17,代碼來源:ConfigurationManagerTest.java

示例11: createReporter

import io.dropwizard.jackson.Jackson; //導入依賴的package包/類
private ScheduledReporter createReporter(String json)
        throws Exception {
    ObjectMapper objectMapper = Jackson.newObjectMapper();
    ReporterFactory reporterFactory = objectMapper.readValue(json, ReporterFactory.class);

    assertTrue(reporterFactory instanceof DatadogExpansionFilteredReporterFactory);
    DatadogExpansionFilteredReporterFactory datadogReporterFactory = (DatadogExpansionFilteredReporterFactory) reporterFactory;

    // Replace the transport with our own mock for testing

    Transport transport = mock(Transport.class);
    when(transport.prepare()).thenReturn(_request);

    AbstractTransportFactory transportFactory = mock(AbstractTransportFactory.class);
    when(transportFactory.build()).thenReturn(transport);

    datadogReporterFactory.setTransport(transportFactory);

    // Build the reporter
    return datadogReporterFactory.build(_metricRegistry);
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:22,代碼來源:DatadogMetricFilterTest.java

示例12: testJsonSerializeNoDeserialization

import io.dropwizard.jackson.Jackson; //導入依賴的package包/類
@Test
public void testJsonSerializeNoDeserialization() throws Exception {
    LazyJsonMap map = new LazyJsonMap("{\"k1\":\"v1\",\"k2\":\"v2\"}");
    map.put("k2", "v22");
    map.put("k3", "v3");

    ObjectMapper objectMapper = Jackson.newObjectMapper();
    objectMapper.registerModule(new LazyJsonModule());

    // Write to JSON, then read back
    String asJson = objectMapper.writeValueAsString(map);
    Map<String, Object> actual = objectMapper.readValue(asJson, new TypeReference<Map<String, Object>>() {});
    Map<String, Object> expected = ImmutableMap.of("k1", "v1", "k2", "v22", "k3", "v3");
    assertEquals(actual, expected);
    // Serialization should not have forced deserialize
    assertFalse(map.isDeserialized());
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:18,代碼來源:LazyJsonMapTest.java

示例13: testJsonSerializeAfterDeserialization

import io.dropwizard.jackson.Jackson; //導入依賴的package包/類
@Test
public void testJsonSerializeAfterDeserialization() throws Exception {
    LazyJsonMap map = new LazyJsonMap("{\"k1\":\"v1\",\"k2\":\"v2\"}");
    map.put("k2", "v22");
    map.put("k3", "v3");
    // Perform a size call which should force the map to deserialize
    map.size();
    assertTrue(map.isDeserialized());

    ObjectMapper objectMapper = Jackson.newObjectMapper();
    objectMapper.registerModule(new LazyJsonModule());

    // Write to JSON, then read back
    String asJson = objectMapper.writeValueAsString(map);
    Map<String, Object> actual = objectMapper.readValue(asJson, new TypeReference<Map<String, Object>>() {});
    Map<String, Object> expected = ImmutableMap.of("k1", "v1", "k2", "v22", "k3", "v3");
    assertEquals(actual, expected);
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:19,代碼來源:LazyJsonMapTest.java

示例14: should_make_a_copy_of_iterable_properties_without_empty_values

import io.dropwizard.jackson.Jackson; //導入依賴的package包/類
@Test
public void should_make_a_copy_of_iterable_properties_without_empty_values() throws JsonProcessingException {
    ObjectMapper mapper = Jackson.newObjectMapper();

    // Iterable properties
    IterableValorisation.IterableValorisationItem itemIterable2 = new IterableValorisation.IterableValorisationItem("blockOfProperties", Sets.newHashSet(new KeyValueValorisation("name3", "value"), new KeyValueValorisation("name0", "")));
    IterableValorisation iterableValorisation2 = new IterableValorisation("iterable2", Lists.newArrayList(itemIterable2));

    IterableValorisation.IterableValorisationItem item = new IterableValorisation.IterableValorisationItem("blockOfProperties", Sets.newHashSet(new KeyValueValorisation("name2", "value"), iterableValorisation2, new KeyValueValorisation("name3", "value3")));
    IterableValorisation iterableValorisation = new IterableValorisation("iterable", Lists.newArrayList(item));

    Properties properties = new Properties(Sets.newHashSet(), Sets.newHashSet(iterableValorisation));

    Properties propertiesCleaned = properties.makeCopyWithoutNullOrEmptyValorisations();

    IterableValorisation.IterableValorisationItem itemIterable2C = new IterableValorisation.IterableValorisationItem("blockOfProperties", Sets.newHashSet(new KeyValueValorisation("name3", "value")));
    IterableValorisation iterableValorisation2C = new IterableValorisation("iterable2", Lists.newArrayList(itemIterable2C));

    IterableValorisation.IterableValorisationItem itemC = new IterableValorisation.IterableValorisationItem("blockOfProperties", Sets.newHashSet(new KeyValueValorisation("name2", "value"), iterableValorisation2C, new KeyValueValorisation("name3", "value3")));
    IterableValorisation iterableValorisationC = new IterableValorisation("iterable", Lists.newArrayList(itemC));

    String propertiesCleanedJSON = mapper.writeValueAsString(propertiesCleaned);
    String expectedJSON = mapper.writeValueAsString(new Properties(Sets.newHashSet(), Sets.newHashSet(iterableValorisationC)));

    assertThat(propertiesCleanedJSON.equals(expectedJSON)).isTrue();
}
 
開發者ID:voyages-sncf-technologies,項目名稱:hesperides,代碼行數:27,代碼來源:PropertiesTest.java

示例15: apply

import io.dropwizard.jackson.Jackson; //導入依賴的package包/類
@Override public Statement apply(final Statement base, Description description) {
  return new Statement() {
    @Override public void evaluate() throws Throwable {
      File yamlFile = new File(Resources.getResource("keywhiz-test.yaml").getFile());
      Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
      ObjectMapper objectMapper = KeywhizService.customizeObjectMapper(Jackson.newObjectMapper());
      KeywhizConfig config = new ConfigurationFactory<>(KeywhizConfig.class, validator, objectMapper, "dw")
          .build(yamlFile);

      DataSource dataSource = config.getDataSourceFactory()
          .build(new MetricRegistry(), "db-migrations");

      Flyway flyway = new Flyway();
      flyway.setDataSource(dataSource);
      flyway.setLocations(config.getMigrationsDir());
      flyway.clean();
      flyway.migrate();

      DSLContext dslContext = DSLContexts.databaseAgnostic(dataSource);
      DbSeedCommand.doImport(dslContext);

      base.evaluate();
    }
  };
}
 
開發者ID:square,項目名稱:keywhiz,代碼行數:26,代碼來源:MigrationsRule.java


注:本文中的io.dropwizard.jackson.Jackson類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。