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:nats.codec.ConnectBody.java

public static ConnectBody parse(String body) {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    try {/*from   www.j  av a  2  s. c  o  m*/
        return mapper.readValue(body, ConnectBody.class);
    } catch (IOException e) {
        throw new NatsException(e);
    }
}

From source file:org.opendaylight.nic.bgp.service.parser.BgpDataflowParser.java

private static ObjectMapper createObjectMapper() {
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
    return objectMapper;
}

From source file:com.mapr.synth.samplers.FieldSampler.java

public static FieldSampler newSampler(String def) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
    mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);

    return mapper.readValue(def, new TypeReference<FieldSampler>() {
    });/*from ww w  .ja v a2s. c o m*/
}

From source file:com.netflix.spinnaker.halyard.core.GlobalApplicationOptions.java

public static GlobalApplicationOptions getInstance() {
    if (GlobalApplicationOptions.options == null) {
        Yaml yamlParser = new Yaml(new SafeConstructor());
        ObjectMapper objectMapper = new ObjectMapper();

        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES, false);
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

        try {//from ww  w. j a va  2s  . co  m
            GlobalApplicationOptions.options = objectMapper.convertValue(
                    yamlParser.load(FileUtils.openInputStream(new File(CONFIG_PATH))),
                    GlobalApplicationOptions.class);
        } catch (IOException e) {
            GlobalApplicationOptions.options = new GlobalApplicationOptions();
        }
    }
    return GlobalApplicationOptions.options;
}

From source file:com.mac.holdempoker.socket.JsonConverter.java

public static String toJsonString(Object obj) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();

    //configure Object mapper for pretty print
    objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);

    //writing to console, can write to any output stream such as file
    StringWriter jsonString = new StringWriter();
    objectMapper.writeValue(jsonString, obj);
    return jsonString.toString();
}

From source file:org.jongo.marshall.jackson.JacksonProcessor.java

public static ObjectMapper createPreConfiguredMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(AUTO_DETECT_GETTERS, false);
    mapper.configure(AUTO_DETECT_SETTERS, false);
    mapper.setSerializationInclusion(NON_NULL);
    mapper.setVisibilityChecker(VisibilityChecker.Std.defaultInstance().withFieldVisibility(ANY));

    SimpleModule module = new SimpleModule("jongo", new Version(1, 0, 0, null, null, null));
    addBSONTypeSerializers(module);//from w  w w.j  ava2  s . c o m
    mapper.registerModule(module);
    return mapper;
}

From source file:org.mango.marshall.jackson.JacksonProcessor.java

public static ObjectMapper createPreConfiguredMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(AUTO_DETECT_GETTERS, false);
    mapper.configure(AUTO_DETECT_SETTERS, false);
    mapper.setSerializationInclusion(NON_NULL);
    mapper.setVisibilityChecker(VisibilityChecker.Std.defaultInstance().withFieldVisibility(ANY));

    SimpleModule module = new SimpleModule("mango", new Version(1, 0, 0, null, null, null));
    addBSONTypeSerializers(module);/*from  w  w  w  .  java 2s  .co m*/
    mapper.registerModule(module);
    return mapper;
}

From source file:com.linecorp.bot.servlet.LineBotCallbackRequestParser.java

private static ObjectMapper buildObjectMapper() {
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    // Register JSR-310(java.time.temporal.*) module and read number as millsec.
    objectMapper.registerModule(new JavaTimeModule())
            .configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
    return objectMapper;
}

From source file:java2typescript.jaxrs.model.RestService.java

/**
 * Dump a JSON representation of the REST services
 *//*from w  ww.  j a v a  2  s . co m*/
static public void toJSON(Collection<RestService> services, Writer writer)
        throws JsonGenerationException, JsonMappingException, IOException {

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

    List<RestService> restServivcesWithoutParams = new ArrayList<RestService>();
    for (RestService restService : services) {
        restServivcesWithoutParams.add(copyWithoutContextParams(restService));
    }

    mapper.writeValue(writer, restServivcesWithoutParams);
}

From source file:com.simple.toadiot.rtinfosdk.util.ParserUtil.java

public static ObjectMapper getObjectMapper() {
    if (objectMapper == null) {
        ObjectMapper retval = new ObjectMapper();
        retval.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
        retval.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        retval.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
        retval.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH, false);
        retval.configure(SerializationFeature.EAGER_SERIALIZER_FETCH, false);
        objectMapper = retval;/*  ww  w  . ja  v a  2  s  .  com*/
    }
    return objectMapper;
}