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

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

Introduction

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

Prototype

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

Source Link

Usage

From source file:com.cloudera.exhibit.server.JsonTest.java

@Before
public void setUp() throws Exception {
    SimpleModule mod = new SimpleModule("exhibit", Version.unknownVersion());
    mod.addSerializer(Exhibit.class, new ExhibitSerializer());
    mod.addSerializer(Frame.class, new FrameSerializer());
    mapper = new ObjectMapper();
    mapper.registerModule(mod);/*from  ww w.  j a v a2  s  . c o m*/
}

From source file:org.cryptomator.ui.model.VaultObjectMapperProvider.java

@Override
public ObjectMapper get() {
    final ObjectMapper om = new ObjectMapper();
    final SimpleModule module = new SimpleModule("VaultJsonMapper");
    module.addSerializer(Vault.class, new VaultSerializer());
    module.addDeserializer(Vault.class, new VaultDeserializer());
    om.registerModule(module);/*w w w.  ja  v  a2s. c  om*/
    return om;
}

From source file:ca.ualberta.physics.cssdp.configuration.JSONObjectMapperProvider.java

public JSONObjectMapperProvider() {

    mapper = new ObjectMapper();
    // mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    // mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    SimpleModule module = new SimpleModule("cicstart");

    module.addSerializer(DateTime.class, new JSONDateTimeSerializer());
    module.addDeserializer(DateTime.class, new JSONDateTimeDeserializer());

    module.addSerializer(LocalDate.class, new JSONLocalDateSerializer());
    module.addDeserializer(LocalDate.class, new JSONLocalDateDeserializer());

    module.addSerializer(LocalDateTime.class, new JSONLocalDateTimeSerializer());
    module.addDeserializer(LocalDateTime.class, new JSONLocalDateTimeDeserializer());

    module.addSerializer(URI.class, new JSONURISerializer());
    module.addDeserializer(URI.class, new JSONURIDeserializer());

    module.addSerializer(new JSONClassSerializer());
    module.addDeserializer(Class.class, new JSONClassDeserializer());

    module.addSerializer(new JSONMnemonicSerializer());
    module.addDeserializer(Mnemonic.class, new JSONMnemonicDeserializer());

    mapper.registerModule(module);/*ww  w .  j ava  2  s.c om*/

}

From source file:com.strategicgains.restexpress.serialization.json.DefaultJsonProcessor.java

/**
 * Template method for sub-classes to augment the module with desired
 * serializers and/or deserializers.  Sub-classes should call super()
 * to get default settings.//from  w  ww.jav  a2 s.c  o  m
 * 
 * @param module a SimpleModule
 */
protected void initializeModule(SimpleModule module) {
    module.addSerializer(Date.class, new JacksonTimepointSerializer()).addDeserializer(Date.class,
            new JacksonTimepointDeserializer());
    initialize(module);
}

From source file:org.jaqpot.core.data.serialize.JacksonMongoSerializer.java

public JacksonMongoSerializer() {
    this.mapper = new ObjectMapper();
    SimpleModule module = new SimpleModule();
    module.addSerializer(DataEntry.class, new DataEntrySerializer());
    mapper.registerModule(module.setDeserializerModifier(new DataEntryDeSerializeModifier()));
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}

From source file:io.apptik.comm.jus.converter.JacksonRequestTest.java

@Before
public void setUp() {
    queue = Jus.newRequestQueue();/*from  ww w  .  j a va2  s .  c o m*/
    SimpleModule module = new SimpleModule();
    module.addSerializer(AnInterface.class, new AnInterfaceSerializer());
    module.addDeserializer(AnInterface.class, new AnInterfaceDeserializer());
    mapper = new ObjectMapper();
    mapper.registerModule(module);
    mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
    mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
    mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
    mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY));

}

From source file:org.n52.tamis.core.test.serialize.ExecuteInputSerializer_Test.java

@Before
public void setupMapper() {
    input_WpsProxySerializer = new ExecuteInputSerializer();

    mapper = new ObjectMapper();

    SimpleModule module = new SimpleModule();
    module.addSerializer(ExecuteInput.class, input_WpsProxySerializer);
    mapper.registerModule(module);//w w  w.j  av  a 2 s. c  o m
}

From source file:uk.ac.ebi.eva.server.ws.EvaWSServer.java

@Bean
public Jackson2ObjectMapperBuilder jacksonBuilder() {
    Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
            .mixIn(VariantSourceEntry.class, VariantSourceEntryJsonMixin.class)
            .mixIn(Genotype.class, GenotypeJsonMixin.class)
            .mixIn(VariantStats.class, VariantStatsJsonMixin.class)
            .mixIn(VariantSource.class, VariantSourceJsonMixin.class).serializationInclusion(Include.NON_NULL);

    SimpleModule module = new SimpleModule();
    module.addSerializer(VariantStats.class, new VariantStatsJsonSerializer());
    builder.modules(module);//  w w  w .  j  a  va  2  s.c  om

    return builder;
}

From source file:io.apptik.comm.jus.converter.JacksonConverterFactoryTest.java

@Before
public void setUp() {
    queue = Jus.newRequestQueue();/* ww  w  .  j  a  v a2 s  .  c o  m*/
    SimpleModule module = new SimpleModule();
    module.addSerializer(AnInterface.class, new AnInterfaceSerializer());
    module.addDeserializer(AnInterface.class, new AnInterfaceDeserializer());
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(module);
    mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
    mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
    mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
    mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY));

    RetroProxy retroProxy = new RetroProxy.Builder().baseUrl(server.url("/").toString())
            .addConverterFactory(JacksonConverterFactory.create(mapper)).requestQueue(queue).build();
    service = retroProxy.create(Service.class);
}

From source file:br.com.criativasoft.opendevice.core.json.CommandJacksonMapper.java

public ObjectMapper getMapper() {
    if (mapper == null) {
        mapper = new ObjectMapper();

        // Uses Enum.toString() for serialization of an Enum
        mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
        // Uses Enum.toString() for deserialization of an Enum
        mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);

        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        SimpleModule module = new SimpleModule("OpenDeviceModule", new Version(0, 1, 0, "alpha"));

        module.addSerializer(CommandType.class, new EnumCodeSerializer());
        module.addDeserializer(CommandType.class, new EnumCodeDeserialize.CommandTypeDeserialize());
        mapper.registerModule(module);/* ww w  .j  a v a 2s  . c o m*/

        module.addDeserializer(Command.class, new CommandDeserialize());

        //mapper.enableDefaultTyping();
        //mapper.setDefaultTyping(new ObjectMapper.DefaultTypeResolverBuilder());

        //
        //            List<Class<? extends  Command>> classList = new ArrayList<Class<? extends Command>>();
        //            classList.add(Command.class);
        //            classList.add(ResponseCommand.class);
        //            classList.add(GetDevicesCommand.class);
        //
        //            for (Class<? extends Command> aClass : classList) {
        //                mapper.addMixInAnnotations(aClass, JsonCommand.class);
        //            }

        //mapper.getSubtypeResolver().registerSubtypes(new NamedType());
    }
    return mapper;
}