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.xeiam.xchange.mtgox.v0.service.marketdata.TradesJSONTest.java

@Test
public void testUnmarshal() throws IOException {

    // Read in the JSON from the example resources
    InputStream is = TradesJSONTest.class.getResourceAsStream("/v0/marketdata/example-trades-data-v0.json");

    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    MtGoxTrade[] mtGoxTrades = mapper.readValue(is, MtGoxTrade[].class);

    // Verify that the example data was unmarshalled correctly
    assertThat(mtGoxTrades[0].getPriceInt()).isEqualTo(1675000L);
}

From source file:com.xeiam.xchange.mtgox.v1.service.trade.OpenOrdersJSONTest.java

@Test
public void testUnmarshal() throws IOException {

    // Read in the JSON from the example resources
    InputStream is = OpenOrdersJSONTest.class.getResourceAsStream("/v1/trade/example-openorders-data.json");

    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    MtGoxOpenOrder[] mtGoxOpenOrders = mapper.readValue(is, MtGoxOpenOrder[].class);

    // Verify that the example data was unmarshalled correctly
    assertThat(mtGoxOpenOrders[0].getOid()).isEqualTo("055e81e4-fe38-4b3c-bbca-69e61724f64a");
}

From source file:com.xeiam.xchange.blockchain.AddressJSONTest.java

@Test
public void testUnmarshal() throws IOException {

    // Read in the JSON from the example resources
    InputStream is = AddressJSONTest.class.getResourceAsStream("/address.json");

    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    BitcoinAddress address = mapper.readValue(is, BitcoinAddress.class);

    // Verify that the example data was unmarshalled correctly
    assertThat(address.getNumTransactions()).isEqualTo(59);
    assertThat(address.getFinalBalance()).isEqualTo(78399012);
    assertThat(address.getFinalBalanceDecimal()).isEqualTo(new BigDecimal(".78399012"));
    assertThat(address.getAddress()).isEqualTo("17dQktcAmU4urXz7tGk2sbuiCqykm3WLs6");
}

From source file:com.xeiam.xchange.mtgox.v1.service.account.AccountInfoJSONTest.java

@Test
public void testUnmarshal() throws IOException {

    // Read in the JSON from the example resources
    InputStream is = AccountInfoJSONTest.class.getResourceAsStream("/v1/account/example-accountinfo-data.json");

    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    MtGoxAccountInfo mtGoxAccountInfo = mapper.readValue(is, MtGoxAccountInfo.class);

    // Verify that the example data was unmarshalled correctly
    assertThat(mtGoxAccountInfo.getLogin()).isEqualTo("xchange");
}

From source file:com.xeiam.xchange.mtgox.v2.service.trade.polling.OpenOrdersJSONTest.java

@Test
public void testUnmarshal() throws IOException {

    // Read in the JSON from the example resources
    InputStream is = OpenOrdersJSONTest.class
            .getResourceAsStream("/v2/trade/polling/example-openorders-data.json");

    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    MtGoxOpenOrder[] mtGoxOpenOrders = mapper.readValue(is, MtGoxOpenOrder[].class);

    // System.out.println(new Date(mtGoxOpenOrders[0].getDate()));

    // Verify that the example data was unmarshalled correctly
    assertThat(mtGoxOpenOrders[0].getOid()).isEqualTo("055e81e4-fe38-4b3c-bbca-69e61724f64a");
}

From source file:com.egreen.tesla.widget.api.service.ServiceBuilder.java

public Map callService(String name, Object... objects)
        throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException {
    Method method = methodMap.get(name);
    Object invoke = method.invoke(instance, objects);

    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    StringWriter stringEmp = new StringWriter();
    objectMapper.writeValue(stringEmp, invoke);
    return objectMapper.readValue(stringEmp.toString(), Map.class);
}

From source file:com.xeiam.xchange.mtgox.v1.service.marketdata.polling.DepthJSONTest.java

@Test
public void testUnmarshal() throws IOException {

    // Read in the JSON from the example resources
    InputStream is = DepthJSONTest.class.getResourceAsStream("/v1/marketdata/polling/example-depth-data.json");

    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    MtGoxDepth mtGoxDepth = mapper.readValue(is, MtGoxDepth.class);

    // Verify that the example data was unmarshalled correctly
    assertThat(mtGoxDepth.getAsks().get(0).getAmountInt()).isEqualTo(246297453L);
    assertThat(mtGoxDepth.getFilterMaxPrice().getValueInt()).isEqualTo(20021100L);
}

From source file:com.xeiam.xchange.mtgox.v1.service.marketdata.polling.TradesJSONTest.java

@Test
public void testUnmarshal() throws IOException {

    // Read in the JSON from the example resources
    InputStream is = TradesJSONTest.class
            .getResourceAsStream("/v1/marketdata/polling/example-trades-data.json");

    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    MtGoxTrade[] mtGoxTrades = mapper.readValue(is, MtGoxTrade[].class);

    // Verify that the example data was unmarshalled correctly
    assertThat(mtGoxTrades[0].getPriceInt()).isEqualTo(19399989L);
}

From source file:com.xeiam.xchange.oer.dto.marketdata.TestOERTickers.java

@Test
public void testUnmarshal() throws IOException {

    // Read in the JSON from the example resources
    InputStream is = TestOERTickers.class.getResourceAsStream("/example-latest-rates.json");

    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    OERTickers oERTickers = mapper.readValue(is, OERTickers.class);

    // Verify that the example data was unmarshalled correctly
    System.out.println(oERTickers.getTimestamp().toString());
    assertThat(oERTickers.getTimestamp()).isEqualTo(1354687208L);

    System.out.println(oERTickers.getRates().getAED());
    assertThat(oERTickers.getRates().getAED()).isEqualTo(3.672989);
}

From source file:io.github.cdelmas.spike.restlet.infrastructure.JacksonCustomConverter.java

private ObjectMapper createMapper() {
    JsonFactory jsonFactory = new JsonFactory();
    jsonFactory.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
    ObjectMapper mapper = new ObjectMapper(jsonFactory);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.registerModule(new Jdk8Module());
    return mapper;
}