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

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

Introduction

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

Prototype

public ObjectMapper disable(SerializationFeature f) 

Source Link

Document

Method for enabling specified DeserializationConfig features.

Usage

From source file:com.nike.cerberus.server.config.CmsConfig.java

public static ObjectMapper configureObjectMapper() {
    final ObjectMapper om = new ObjectMapper();
    om.findAndRegisterModules();/*from   w  ww.  j av a  2 s.  co  m*/
    om.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
    om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    om.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    om.enable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);
    om.enable(SerializationFeature.INDENT_OUTPUT);
    return om;
}

From source file:io.coala.json.JsonUtil.java

/**
 * @param instance//from   w  w  w.  j a v  a2 s .  c  om
 */
public synchronized static void initialize(final ObjectMapper om) {
    om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);

    final Module[] modules = { new JodaModule(), new UUIDModule(), new JavaTimeModule() };
    om.registerModules(modules);
    LOG.trace("Using jackson v: {} with modules: {}", om.version(),
            Arrays.asList(modules).stream().map(m -> m.getModuleName()).collect(Collectors.toList()));
}

From source file:io.github.cdelmas.spike.sparkjava.Main.java

private static ObjectMapper createObjectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {
        @Override/*w w  w. jav  a 2 s. c o m*/
        public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers)
                throws IOException, JsonProcessingException {
        }
    });
    objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    return objectMapper;
}

From source file:com.modelon.oslc.adapter.fmi.integration.FMUConnector.java

public static FMU loadSingleFMU(String fmuInterfaceCMDPath, String fmuPath, String unzipTempDir)
        throws IOException {
    File cmd = new File(fmuInterfaceCMDPath);
    File fmu = new File(fmuPath);
    File fmuTempDir = new File(unzipTempDir + File.separator + fmu.getName());
    fmuTempDir.mkdirs();// ww w  .j  a  v a  2  s  .c  o  m

    try {
        ProcessBuilder builder = new ProcessBuilder(cmd.getPath(), "read", fmu.getPath(), fmuTempDir.getPath());
        builder.redirectErrorStream(true);
        Process p = builder.start();

        BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
        StringBuilder sbuilder = new StringBuilder();
        String aux = "";

        while ((aux = reader.readLine()) != null) {
            aux = aux.replaceAll("\\\\", "\\\\\\\\");
            aux += "\r\n";
            sbuilder.append(aux);
        }

        String json = sbuilder.toString();
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
        FMU fmuObject = mapper.readValue(json, FMU.class);
        if (fmuObject.fmiVersion != null)
            return mapper.readValue(json, FMU.class);
        else
            return null;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.addthis.codec.jackson.Jackson.java

public static ObjectMapper toggleObjectMapperOptions(ObjectMapper objectMapper) {
    // potentially useful features, but disabled by default to maintain existing behavior

    // ignore final fields
    objectMapper.disable(ALLOW_FINAL_FIELDS_AS_MUTATORS);
    // do not try to modify existing containers
    objectMapper.disable(USE_GETTERS_AS_SETTERS);
    // public getters do not automaticaly imply codec should try to write to it
    objectMapper.disable(INFER_PROPERTY_MUTATORS);

    // more aggressive failure detection
    objectMapper.enable(FAIL_ON_READING_DUP_TREE_KEY);

    // essentially auto-collection everywhere, but that seems fine and this is easy
    objectMapper.enable(ACCEPT_SINGLE_VALUE_AS_ARRAY);

    // don't write out null fields
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return objectMapper;
}

From source file:com.twitter.ambrose.util.JSONUtil.java

private static ObjectMapper newMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
    mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false);
    mapper.disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE);
    mapper.disable(SerializationFeature.CLOSE_CLOSEABLE);
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

    Reflections reflections = new Reflections("com.twitter.ambrose");
    Set<Class<? extends Job>> jobSubTypes = reflections.getSubTypesOf(Job.class);
    mapper.registerSubtypes(jobSubTypes.toArray(new Class<?>[jobSubTypes.size()]));
    return mapper;
}

From source file:com.yahoo.gondola.container.Utils.java

public static ObjectMapper getObjectMapperInstance() {
    if (objectMapper == null) {
        ObjectMapper mapper = new ObjectMapper();
        mapper.enable(SerializationFeature.WRITE_NULL_MAP_VALUES);
        mapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE);
        mapper.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.NONE);
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
        objectMapper = mapper;/* w w w  .java  2s  .c om*/
    }
    return objectMapper;
}

From source file:com.infinities.skyport.util.JsonUtil.java

public static ObjectMapper getObjectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper = objectMapper.setAnnotationIntrospector(jaxbAnnotationPair);
    // make deserializer use JAXB annotations (only)
    objectMapper = objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    objectMapper = objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    // objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
    objectMapper.configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, true);
    return objectMapper;
}

From source file:org.hawkular.rest.ResponseUtil.java

private static <T> InputStream pageToStream(Page<T> page, ObjectMapper mapper, Runnable callback)
        throws IOException {
    final PipedOutputStream outs = new PipedOutputStream();
    final PipedInputStream ins = new PipedInputStream() {
        @Override/*  www  .  j a v  a  2 s  . c om*/
        public void close() throws IOException {
            outs.close();
            super.close();
        }
    };
    outs.connect(ins);
    mapper.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);

    PageToStreamThreadPool.getInstance().submit(() -> {
        try (Page<T> closeablePage = page;
                PipedOutputStream out = outs;
                SequenceWriter sequenceWriter = mapper.writer().writeValuesAsArray(out)) {
            for (T element : closeablePage) {
                sequenceWriter.write(element);
                sequenceWriter.flush();
            }
        } catch (IOException e) {
            throw new IllegalStateException("Unable to convert page to input stream.", e);
        } finally {
            callback.run();
        }
    });
    return ins;
}

From source file:de.taimos.dvalin.interconnect.model.InterconnectMapper.java

private static ObjectMapper createMapper() {
    ObjectMapper mapper = new ObjectMapper();
    JodaModule jm = new JodaModule();
    // make some modifications to ensure correct tz serialization and get map keys working
    jm.addKeyDeserializer(DateTime.class, new DateTimeKeyDeserializer());
    jm.addDeserializer(DateTime.class, new DateTimeDeserializerWithTZ());
    mapper.registerModule(jm);//from   ww w . j a va 2  s  .com
    mapper.registerModule(new GuavaModule());
    mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    return mapper;
}