Example usage for com.fasterxml.jackson.databind ObjectMapper configure

List of usage examples for com.fasterxml.jackson.databind ObjectMapper configure

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper configure.

Prototype

public ObjectMapper configure(JsonGenerator.Feature f, boolean state) 

Source Link

Document

Method for changing state of an on/off JsonGenerator feature for JsonFactory instance this object mapper uses.

Usage

From source file:com.miserablemind.api.consumer.tradeking.api.impl.TradeKingTemplate.java

@Override
protected MappingJackson2HttpMessageConverter getJsonMessageConverter() {
    MappingJackson2HttpMessageConverter converter = super.getJsonMessageConverter();

    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true);
    mapper.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true);
    mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
    mapper.registerModule(new TradeKingModule());
    mapper.registerModule(new JodaModule());
    converter.setObjectMapper(mapper);//from  w  w  w.  ja  v  a 2  s  .c o m
    return converter;
}

From source file:com.xeiam.xchange.mtgox.v2.service.marketdata.polling.streaming.TickerJSONTest.java

@Test
public void testStreamingUnmarshal() throws IOException {

    // Read in the JSON from the example resources
    InputStream is = TickerJSONTest.class
            .getResourceAsStream("/v2/marketdata/streaming/example-ticker-streaming-data.json");

    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    Map<String, Object> userInMap = mapper.readValue(is, new TypeReference<Map<String, Object>>() {
    });/*from   www  .  j  a  v  a 2s  .  c o  m*/

    // Use Jackson to parse it
    mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    MtGoxTicker mtGoxTicker = mapper.readValue(mapper.writeValueAsString(userInMap.get("ticker")),
            MtGoxTicker.class);

    // Verify that the example data was unmarshalled correctly
    assertThat(mtGoxTicker.getBuy().getValue()).isEqualTo(new BigDecimal("90.78469"));
    assertThat(mtGoxTicker.getNow()).isEqualTo(1364667533416136L);

}

From source file:net.hydromatic.optiq.impl.csv.JsonEnumerator.java

public JsonEnumerator(File file) {
    try {//from  w  ww . j ava 2 s . c om
        final ObjectMapper mapper = new ObjectMapper();
        mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
        mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
        mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
        //noinspection unchecked
        List<Object> list = mapper.readValue(file, List.class);
        enumerator = Linq4j.enumerator(list);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.calcite.adapter.csv.JsonEnumerator.java

public JsonEnumerator(File file) {
    try {/*w w w. j  a  va2 s .com*/
        final ObjectMapper mapper = new ObjectMapper();
        mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
        mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
        mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
        // noinspection unchecked
        List<Object> list = mapper.readValue(file, List.class);
        enumerator = Linq4j.enumerator(list);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.openwms.TransportationStarter.java

public @Primary @Bean(name = TMSConstants.BEAN_NAME_OBJECTMAPPER) ObjectMapper jackson2ObjectMapper() {
    ObjectMapper om = new ObjectMapper();
    om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    om.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
    om.configure(SerializationFeature.INDENT_OUTPUT, true);
    om.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
    om.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    return om;//w  w w  .  j  av a 2s.c o  m
}

From source file:io.github.cdelmas.spike.dropwizard.infrastructure.DropwizardApplication.java

@Override
public void initialize(Bootstrap<DropwizardServerConfiguration> bootstrap) {
    guiceBundle = GuiceBundle.<DropwizardServerConfiguration>newBuilder().addModule(new HelloModule())
            .addModule(new CarModule()).setConfigClass(DropwizardServerConfiguration.class).build();
    bootstrap.addBundle(guiceBundle);//from  w  ww. j a  v  a  2  s. c  o m
    bootstrap.addBundle(new Java8Bundle());

    ObjectMapper objectMapper = bootstrap.getObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}

From source file:org.switchyard.quickstarts.transform.datamapper.FileBindingsTest.java

private String jsonUnprettyPrint(String jsonString) throws JsonProcessingException, IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
    JsonNode node = mapper.readTree(jsonString);
    return node.toString();
}

From source file:com.ning.metrics.goodwill.access.GoodwillAccessorTest.java

@Test(enabled = false, groups = "slow")
public void testIntegration() throws Exception {
    GoodwillAccessor accessor = new GoodwillAccessor("localhost", 8080);

    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.INDENT_OUTPUT, true);

    Future<List<GoodwillSchema>> thrifts = accessor.getSchemata();

    List<GoodwillSchema> schemata = thrifts.get();
    // Simple test to make sure we got actual GoodwillSchema, 0.0.5 has the following bug:
    // java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.ning.metrics.goodwill.access.GoodwillSchema
    Assert.assertTrue(schemata.get(0).getName().length() > 0);

    System.out.println(String.format("All thrifts:\n%s", mapper.writeValueAsString(schemata)));

    Future<GoodwillSchema> thrift = accessor.getSchema("Awesomeness");

    GoodwillSchema schema = thrift.get();
    Assert.assertTrue(schema.getName().length() > 0);

    System.out.println(String.format("Awesomeness thrift:\n%s", mapper.writeValueAsString(schema)));

    accessor.close();//from   www . j  ava2s .  c o m
}

From source file:com.iflytek.edu.cloud.frame.spring.MappingJackson2HttpMessageConverterExt.java

public MappingJackson2HttpMessageConverterExt() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    objectMapper.setDateFormat(dateFormat);
    this.setObjectMapper(objectMapper);
}

From source file:com.strandls.alchemy.inject.AlchemyModuleFilterConfigurationTest.java

/**
 * Setup expected result.//from ww  w . j  av  a  2  s . c om
 *
 * @throws JsonParseException
 * @throws JsonMappingException
 * @throws IOException
 */
@Before
public void setup() throws JsonParseException, JsonMappingException, IOException {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.configure(Feature.ALLOW_SINGLE_QUOTES, true);
    expectedResult = mapper.readValue(
            "{'Prod' : ['(?i).*dummy.*'], 'Test':['ToFilter1', 'ToFilter2'],"
                    + " 'All':['(?i).*dummy.*', 'ToFilter1', 'ToFilter2']}",
            new TypeReference<Map<Environment, Set<String>>>() {
            });
}