All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.treasuredata.client.model.ObjectMappers Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package com.treasuredata.client.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule;
import com.google.common.annotations.VisibleForTesting;

@VisibleForTesting
public class ObjectMappers
{
    private ObjectMappers()
    {
    }

    /**
     * Lazy instantiation wrapper.
     */
    private static class Lazy
    {
        private static final ObjectMapper COMPACT_MAPPER = createCompactMapper();
    }

    /**
     * Get an {@link ObjectMapper} that omits null and absent fields.
     */
    @VisibleForTesting
    public static ObjectMapper compactMapper()
    {
        return Lazy.COMPACT_MAPPER;
    }

    private static ObjectMapper createCompactMapper()
    {
        ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(new JsonOrgModule());
        mapper.registerModule(new GuavaModule().configureAbsentsAsNulls(false));
        mapper.setSerializationInclusion(JsonInclude.Include.NON_ABSENT);
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        return mapper;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy