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

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


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


public boolean canSerialize(Class<?> type) 

Source Link


Method that can be called to check whether mapper thinks it could serialize an instance of given Class.


From source file:com.feedzai.fos.api.ModelConfigTest.java

public void testJacksonSerialization() throws IOException {
    CategoricalAttribute categorical = new CategoricalAttribute("categoric", Arrays.asList("abc", "def"));
    NumericAttribute numeric = new NumericAttribute("numeric");

    List<Attribute> attributes = Arrays.<Attribute>asList(categorical, numeric);

    Map<String, String> properties = new HashMap<>();
    properties.put("p1", "value1");
    properties.put("p2", "value2");

    ModelConfig config = new ModelConfig(attributes, properties);

    ObjectMapper mapper = new ObjectMapper();
    String json = mapper.writeValueAsString(config);

    System.out.println(json);//from  w ww . j a  v  a 2s.c om

    ModelConfig deserialized = mapper.readValue(json, config.getClass());
    assertEquals(config, deserialized);

From source file:org.camunda.spin.impl.json.jackson.format.JacksonJsonDataFormatMapper.java

public boolean canMap(Object parameter) {
    ObjectMapper objectMapper = format.getObjectMapper();
    if (parameter != null) {
        return objectMapper.canSerialize(parameter.getClass());
    } else {/*from  www .  java  2  s.  co  m*/
        return false;