当前位置: 首页>>代码示例>>Java>>正文


Java Jackson.newObjectMapper方法代码示例

本文整理汇总了Java中io.dropwizard.jackson.Jackson.newObjectMapper方法的典型用法代码示例。如果您正苦于以下问题:Java Jackson.newObjectMapper方法的具体用法?Java Jackson.newObjectMapper怎么用?Java Jackson.newObjectMapper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.dropwizard.jackson.Jackson的用法示例。


在下文中一共展示了Jackson.newObjectMapper方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: testParsing

import io.dropwizard.jackson.Jackson; //导入方法依赖的package包/类
@Test
public void testParsing() throws Exception {
    ConfigurationFactory<MacroBaseConf> cfFactory = new ConfigurationFactory<>(MacroBaseConf.class,
                                                                               null,
                                                                               Jackson.newObjectMapper(),
                                                                               "");
    MacroBaseConf conf = cfFactory.build(new File("src/test/resources/conf/simple.yaml"));


    assertEquals((Double) 0.1, conf.getDouble("this.is.a.double"));
    assertEquals((Integer) 100, conf.getInt("this.is.an.integer"));
    assertEquals((Long) 10000000000000L, conf.getLong("this.is.a.long"));
    assertEquals("Test", conf.getString("this.is.a.string"));

    List<String> stringList = Lists.newArrayList("T1", "T2", "T3", "T4");
    assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList").toArray());
    assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList.without.spaces").toArray());
    assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList.with.mixed.spaces").toArray());
}
 
开发者ID:stanford-futuredata,项目名称:macrobase,代码行数:20,代码来源:MacroBaseConfTest.java

示例8: createConfiguration

import io.dropwizard.jackson.Jackson; //导入方法依赖的package包/类
public static OregamiConfiguration createConfiguration(String configFilename) {
    ConfigurationFactory<OregamiConfiguration> factory =
            new ConfigurationFactory<>(
                    OregamiConfiguration.class,
                    Validation.buildDefaultValidatorFactory().getValidator(),
                    Jackson.newObjectMapper(),
                    ""
            );
    OregamiConfiguration configuration;
    try {
        configuration = factory.build(new File(configFilename));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    System.out.println(ToStringBuilder.reflectionToString(configuration, ToStringStyle.MULTI_LINE_STYLE));
    System.out.println(ToStringBuilder.reflectionToString(configuration.getDatabaseConfiguration(), ToStringStyle.MULTI_LINE_STYLE));
    return configuration;
}
 
开发者ID:oregami,项目名称:oregami-server,代码行数:19,代码来源:StartHelper.java

示例9: getPac4jFactory

import io.dropwizard.jackson.Jackson; //导入方法依赖的package包/类
protected Pac4jFactory getPac4jFactory(
        Collection<Pac4jFeatureSupport> featuresSupported,
        String resourceName) throws Exception {
    ObjectMapper om = Jackson.newObjectMapper();
    Bootstrap<?> b = mock(Bootstrap.class);
    when(b.getObjectMapper()).thenReturn(om);

    for (Pac4jFeatureSupport fs : featuresSupported) {
        fs.setup(b);
    }

    return new YamlConfigurationFactory<>(Pac4jFactory.class,
            Validators.newValidator(), om, "dw").build(
                    new File(Resources.getResource(resourceName).toURI()));
}
 
开发者ID:pac4j,项目名称:dropwizard-pac4j,代码行数:16,代码来源:AbstractConfigurationTest.java

示例10: writeEntriesTo_writeRecordView

import io.dropwizard.jackson.Jackson; //导入方法依赖的package包/类
@Test
public void writeEntriesTo_writeRecordView() throws Exception {
    ObjectMapper objectMapper = Jackson.newObjectMapper();

    Entry entry = new Entry(1, new HashValue(HashingAlgorithm.SHA256, "ab"), Instant.ofEpochSecond(1470403440), "key1", EntryType.user);
    Item item = new Item(new HashValue(HashingAlgorithm.SHA256, "aaa"), objectMapper.readTree("{\"key1\":\"item1\"}"));
    Item item2 = new Item(new HashValue(HashingAlgorithm.SHA256, "bbb"), objectMapper.readTree("{\"key1\":\"item2\"}"));
    Record record = new Record(entry, Arrays.asList(item, item2));

    ImmutableMap<String, Field> fields = ImmutableMap.of(
            "key1", new Field("key1", "datatype", new RegisterName("address"), Cardinality.ONE, "text"),
            "key2", new Field("key2", "datatype", new RegisterName("address"), Cardinality.ONE, "text"),
            "key3", new Field("key3", "datatype", new RegisterName("address"), Cardinality.ONE, "text"),
            "key4", new Field("key4", "datatype", new RegisterName("address"), Cardinality.ONE, "text"));

    ItemConverter itemConverter = mock(ItemConverter.class);
    when(itemConverter.convertItem(item, fields)).thenReturn(ImmutableMap.of("key1", new StringValue("item1")));
    when(itemConverter.convertItem(item2, fields)).thenReturn(ImmutableMap.of("key1", new StringValue("item2")));

    RecordView recordView = new RecordView(record, fields, itemConverter);

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    csvWriter.writeTo(recordView, recordView.getClass(), null, null, null, null, outputStream);

    byte[] bytes = outputStream.toByteArray();
    String generatedCsv = new String(bytes, StandardCharsets.UTF_8);

    String expected = "index-entry-number,entry-number,entry-timestamp,key,key1,key2,key3,key4\r\n" +
            "1,1,2016-08-05T13:24:00Z,key1,item1,,,\r\n" +
            "1,1,2016-08-05T13:24:00Z,key1,item2,,,\r\n";

    assertThat(generatedCsv, is(expected));
}
 
开发者ID:openregister,项目名称:openregister-java,代码行数:35,代码来源:CsvWriterTest.java

示例11: ApplicationSearch

import io.dropwizard.jackson.Jackson; //导入方法依赖的package包/类
/**
 * Main constructor.
 *
 * @param elasticSearchClient
 */
public ApplicationSearch(final ElasticSearchClient elasticSearchClient) {
    ObjectMapper objectMapper = Jackson.newObjectMapper();
    JavaType searchType = objectMapper.getTypeFactory().constructParametricType(ElasticSearchResponse.class, ApplicationSearchResponse.class);
    this.elasticSearchVsctApplicationReader = objectMapper.reader(searchType);
    JavaType searchTypePlatform = objectMapper.getTypeFactory().constructParametricType(ElasticSearchResponse.class, PlatformSearchResponse.class);
    this.elasticSearchVsctPlatformReader = objectMapper.reader(searchTypePlatform);
    JavaType searchTypePlatformApplication = objectMapper.getTypeFactory().constructParametricType(ElasticSearchResponse.class, PlatformApplicationSearchResponse.class);
    this.elasticSearchVsctPlatformApplicationReader = objectMapper.reader(searchTypePlatformApplication);
    this.elasticSearchClient = elasticSearchClient;
}
 
开发者ID:voyages-sncf-technologies,项目名称:hesperides,代码行数:16,代码来源:ApplicationSearch.java

示例12: newObjectMapper

import io.dropwizard.jackson.Jackson; //导入方法依赖的package包/类
public static ObjectMapper newObjectMapper() {
    ObjectMapper mapper = Jackson.newObjectMapper();
    //        mapper.registerModule(new JSR310Module());  // Java 8 Instant support
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
    mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false);
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    mapper.configure(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN, true);
    return mapper;
}
 
开发者ID:commercehub-oss,项目名称:clouseau,代码行数:11,代码来源:ObjectMapperFactory.java

示例13: generalMapper

import io.dropwizard.jackson.Jackson; //导入方法依赖的package包/类
@Provides public ObjectMapper generalMapper() {
  /**
   * Customizes ObjectMapper for common settings.
   *
   * @param objectMapper to be customized
   * @return customized input factory
   */
  ObjectMapper objectMapper = Jackson.newObjectMapper();
  objectMapper.registerModule(new Jdk8Module());
  objectMapper.registerModules(new JavaTimeModule());
  objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
  return objectMapper;
}
 
开发者ID:square,项目名称:keywhiz,代码行数:14,代码来源:CliModule.java

示例14: setup

import io.dropwizard.jackson.Jackson; //导入方法依赖的package包/类
@Before
public void setup() {
    reset(competitionGroupSetMapper, competitionGroupSetService);

    objectMapper = Jackson.newObjectMapper();
    JacksonUtil.configureObjectMapper(objectMapper);
}
 
开发者ID:caeos,项目名称:coner-core,代码行数:8,代码来源:CompetitionGroupSetsResourceTest.java

示例15: setup

import io.dropwizard.jackson.Jackson; //导入方法依赖的package包/类
@Before
public void setup() {
    reset(eventMapper, eventEntityService);

    objectMapper = Jackson.newObjectMapper();
    JacksonUtil.configureObjectMapper(objectMapper);
}
 
开发者ID:caeos,项目名称:coner-core,代码行数:8,代码来源:EventsResourceTest.java


注:本文中的io.dropwizard.jackson.Jackson.newObjectMapper方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。