本文整理汇总了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());
}
示例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());
}
示例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());
}
示例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);
}
示例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);
}
}
示例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"));
}
示例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));
}
示例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$"));
}
示例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);
}
示例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();
}
示例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);
}
示例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());
}
示例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);
}
示例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();
}
示例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();
}
};
}