Search in sources :

Example 96 with Jdk8Module

use of io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module in project samza by apache.

the class SamzaObjectMapper method getObjectMapper.

/**
 * @return Returns a new ObjectMapper that's been configured to (de)serialize
 *         Samza's job data model, and simple data types such as TaskName,
 *         Partition, Config, and SystemStreamPartition.
 */
public static ObjectMapper getObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.WRAP_EXCEPTIONS, false);
    mapper.configure(SerializationFeature.WRAP_EXCEPTIONS, false);
    SimpleModule module = new SimpleModule("SamzaModule", new Version(1, 0, 0, ""));
    // Setup custom serdes for simple data types.
    module.addSerializer(Partition.class, new PartitionSerializer());
    module.addSerializer(SystemStreamPartition.class, new SystemStreamPartitionSerializer());
    module.addKeySerializer(SystemStreamPartition.class, new SystemStreamPartitionKeySerializer());
    module.addSerializer(TaskName.class, new TaskNameSerializer());
    module.addSerializer(TaskMode.class, new TaskModeSerializer());
    module.addDeserializer(TaskName.class, new TaskNameDeserializer());
    module.addDeserializer(Partition.class, new PartitionDeserializer());
    module.addDeserializer(SystemStreamPartition.class, new SystemStreamPartitionDeserializer());
    module.addKeyDeserializer(SystemStreamPartition.class, new SystemStreamPartitionKeyDeserializer());
    module.addDeserializer(Config.class, new ConfigDeserializer());
    module.addDeserializer(TaskMode.class, new TaskModeDeserializer());
    module.addSerializer(CheckpointId.class, new CheckpointIdSerializer());
    module.addDeserializer(CheckpointId.class, new CheckpointIdDeserializer());
    // Setup mixins for data models.
    mapper.addMixIn(TaskModel.class, JsonTaskModelMixIn.class);
    mapper.addMixIn(ContainerModel.class, JsonContainerModelMixIn.class);
    mapper.addMixIn(JobModel.class, JsonJobModelMixIn.class);
    mapper.addMixIn(CheckpointV2.class, JsonCheckpointV2Mixin.class);
    mapper.addMixIn(KafkaStateCheckpointMarker.class, KafkaStateCheckpointMarkerMixin.class);
    module.addDeserializer(ContainerModel.class, new JsonDeserializer<ContainerModel>() {

        @Override
        public ContainerModel deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
            ObjectCodec oc = jp.getCodec();
            JsonNode node = oc.readTree(jp);
            /*
         * Before Samza 0.13, "container-id" was used.
         * In Samza 0.13, "processor-id" was added to be the id to use and "container-id" was deprecated. However,
         * "container-id" still needed to be checked for backwards compatibility in case "processor-id" was missing
         * (i.e. from a job model corresponding to a version of the job that was on a pre Samza 0.13 version).
         * In Samza 1.0, "container-id" was further cleaned up from ContainerModel. This logic is still being left here
         * as a fallback for backwards compatibility with pre Samza 0.13. ContainerModel.getProcessorId was changed to
         * ContainerModel.getId in the Java API, but "processor-id" still needs to be used as the JSON key for backwards
         * compatibility with Samza 0.13 and Samza 0.14.
         */
            String id;
            if (node.get(JsonContainerModelMixIn.PROCESSOR_ID_KEY) == null) {
                if (node.get(JsonContainerModelMixIn.CONTAINER_ID_KEY) == null) {
                    throw new SamzaException(String.format("JobModel was missing %s and %s. This should never happen. JobModel corrupt!", JsonContainerModelMixIn.PROCESSOR_ID_KEY, JsonContainerModelMixIn.CONTAINER_ID_KEY));
                }
                id = String.valueOf(node.get(JsonContainerModelMixIn.CONTAINER_ID_KEY).intValue());
            } else {
                id = node.get(JsonContainerModelMixIn.PROCESSOR_ID_KEY).textValue();
            }
            Map<TaskName, TaskModel> tasksMapping = OBJECT_MAPPER.readValue(OBJECT_MAPPER.treeAsTokens(node.get(JsonContainerModelMixIn.TASKS_KEY)), new TypeReference<Map<TaskName, TaskModel>>() {
            });
            return new ContainerModel(id, tasksMapping);
        }
    });
    mapper.addMixIn(LocalityModel.class, JsonLocalityModelMixIn.class);
    mapper.addMixIn(ProcessorLocality.class, JsonProcessorLocalityMixIn.class);
    // Register mixins for job coordinator metadata model
    mapper.addMixIn(JobCoordinatorMetadata.class, JsonJobCoordinatorMetadataMixIn.class);
    // Convert camel case to hyphenated field names, and register the module.
    mapper.setPropertyNamingStrategy(new CamelCaseToDashesStrategy());
    mapper.registerModules(module, new Jdk8Module());
    return mapper;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) SamzaException(org.apache.samza.SamzaException) ContainerModel(org.apache.samza.job.model.ContainerModel) Version(com.fasterxml.jackson.core.Version) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) TypeReference(com.fasterxml.jackson.core.type.TypeReference) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonParser(com.fasterxml.jackson.core.JsonParser) IOException(java.io.IOException) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) TaskName(org.apache.samza.container.TaskName) HashMap(java.util.HashMap) Map(java.util.Map) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) TaskModel(org.apache.samza.job.model.TaskModel)

Example 97 with Jdk8Module

use of io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module in project presto by prestodb.

the class TpchMetadata method createStatisticsEstimator.

private static StatisticsEstimator createStatisticsEstimator() {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new Jdk8Module());
    TableStatisticsDataRepository tableStatisticsDataRepository = new TableStatisticsDataRepository(objectMapper);
    return new StatisticsEstimator(tableStatisticsDataRepository);
}
Also used : Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) StatisticsEstimator(com.facebook.presto.tpch.statistics.StatisticsEstimator) TableStatisticsDataRepository(com.facebook.presto.tpch.statistics.TableStatisticsDataRepository) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 98 with Jdk8Module

use of io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module in project dropwizard by dropwizard.

the class Jackson method configure.

private static ObjectMapper configure(ObjectMapper mapper) {
    mapper.registerModule(new GuavaModule());
    mapper.registerModule(new GuavaExtrasModule());
    mapper.registerModule(new CaffeineModule());
    mapper.registerModule(new JodaModule());
    mapper.registerModule(new BlackbirdModule());
    mapper.registerModule(new FuzzyEnumModule());
    mapper.registerModule(new ParameterNamesModule());
    mapper.registerModule(new Jdk8Module());
    mapper.registerModule(new JavaTimeModule());
    mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
    mapper.setSubtypeResolver(new DiscoverableSubtypeResolver());
    mapper.disable(FAIL_ON_UNKNOWN_PROPERTIES);
    return mapper;
}
Also used : BlackbirdModule(com.fasterxml.jackson.module.blackbird.BlackbirdModule) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) ParameterNamesModule(com.fasterxml.jackson.module.paramnames.ParameterNamesModule) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule)

Example 99 with Jdk8Module

use of io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module in project keywhiz by square.

the class JsonHelpers method customizeObjectMapper.

/**
 * Customized ObjectMapper for common settings.
 *
 * @return customized object mapper
 */
private static ObjectMapper customizeObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new Jdk8Module());
    mapper.registerModule(new GuavaModule());
    mapper.registerModule(new GuavaExtrasModule());
    mapper.registerModule(new FuzzyEnumModule());
    mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
    mapper.setSubtypeResolver(new DiscoverableSubtypeResolver());
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return mapper;
}
Also used : Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) GuavaExtrasModule(io.dropwizard.jackson.GuavaExtrasModule) FuzzyEnumModule(io.dropwizard.jackson.FuzzyEnumModule) DiscoverableSubtypeResolver(io.dropwizard.jackson.DiscoverableSubtypeResolver) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) AnnotationSensitivePropertyNamingStrategy(io.dropwizard.jackson.AnnotationSensitivePropertyNamingStrategy)

Example 100 with Jdk8Module

use of io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module in project dhis2-core by dhis2.

the class JacksonObjectMapperConfig method configureMapper.

/**
 * Shared configuration for all Jackson mappers
 *
 * @param objectMapper an {@see ObjectMapper}
 * @param autoDetectGetters if true, enable `autoDetectGetters`
 * @return a configured {@see ObjectMapper}
 */
private static ObjectMapper configureMapper(ObjectMapper objectMapper, boolean autoDetectGetters) {
    SimpleModule module = new SimpleModule();
    module.addDeserializer(String.class, new EmptyStringToNullStdDeserializer());
    module.addDeserializer(Date.class, new ParseDateStdDeserializer());
    module.addDeserializer(JsonPointer.class, new JsonPointerStdDeserializer());
    module.addSerializer(Date.class, new WriteDateStdSerializer());
    module.addSerializer(JsonPointer.class, new JsonPointerStdSerializer());
    // Registering a custom Instant serializer/deserializer for DTOs using
    // Instant
    JavaTimeModule javaTimeModule = new JavaTimeModule();
    javaTimeModule.addSerializer(Instant.class, new WriteInstantStdSerializer());
    javaTimeModule.addDeserializer(Instant.class, new ParseInstantStdDeserializer());
    objectMapper.registerModules(module, javaTimeModule, new Jdk8Module());
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    objectMapper.setDefaultPropertyInclusion(JsonInclude.Include.NON_NULL);
    objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    objectMapper.enable(SerializationFeature.WRAP_EXCEPTIONS);
    objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    objectMapper.disable(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY);
    objectMapper.enable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES);
    objectMapper.enable(DeserializationFeature.WRAP_EXCEPTIONS);
    objectMapper.disable(MapperFeature.AUTO_DETECT_FIELDS);
    objectMapper.disable(MapperFeature.AUTO_DETECT_CREATORS);
    if (!autoDetectGetters) {
        objectMapper.disable(MapperFeature.AUTO_DETECT_GETTERS);
    }
    objectMapper.disable(MapperFeature.AUTO_DETECT_SETTERS);
    objectMapper.disable(MapperFeature.AUTO_DETECT_IS_GETTERS);
    return objectMapper;
}
Also used : Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Aggregations

Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)153 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)123 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)64 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)30 ParameterNamesModule (com.fasterxml.jackson.module.paramnames.ParameterNamesModule)26 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)22 IOException (java.io.IOException)19 Bean (org.springframework.context.annotation.Bean)13 BeforeClass (org.junit.BeforeClass)11 Test (org.junit.Test)10 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)8 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)8 JSONObject (org.json.JSONObject)8 Autowired (org.springframework.beans.factory.annotation.Autowired)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 MetricRegistry (com.codahale.metrics.MetricRegistry)5 JacksonAnnotationIntrospector (com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector)5 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)5 Action (io.syndesis.common.model.action.Action)5 Test (org.junit.jupiter.api.Test)5