Example usage for com.fasterxml.jackson.databind.module SimpleModule addKeySerializer

List of usage examples for com.fasterxml.jackson.databind.module SimpleModule addKeySerializer

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.module SimpleModule addKeySerializer.

Prototype

public <T> SimpleModule addKeySerializer(Class<? extends T> type, JsonSerializer<T> ser) 

Source Link

Usage

From source file:org.nohope.jongo.JacksonProcessor.java

@Nonnull
private static ObjectMapper createPreConfiguredMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JodaModule());
    mapper.registerModule(new ColorModule());

    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));

    mapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.NON_FINAL,
            JsonTypeInfo.Id.CLASS.getDefaultPropertyName());

    final SimpleModule module = new SimpleModule("jongo", Version.unknownVersion());
    module.addKeySerializer(Object.class, ComplexKeySerializer.S_OBJECT);
    module.addKeyDeserializer(String.class, ComplexKeyDeserializer.S_OBJECT);
    module.addKeyDeserializer(Object.class, ComplexKeyDeserializer.S_OBJECT);

    //addBSONTypeSerializers(module);

    mapper.registerModule(module);//from w w w . j a  va2s .  c  om
    return mapper;
}

From source file:com.proofpoint.json.ObjectMapperProvider.java

@SuppressWarnings("unchecked")
private <T> void addKeySerializer(SimpleModule module, Class<?> type, JsonSerializer<?> keySerializer) {
    module.addKeySerializer((Class<? extends T>) type, (JsonSerializer<T>) keySerializer);
}