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

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

Introduction

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

Prototype

public SimpleModule(String name, Version version) 

Source Link

Document

Constructor to use for actual reusable modules.

Usage

From source file:be.wegenenverkeer.common.resteasy.json.RestJsonMapper.java

/**
 * No-arguments constructor./*from  ww w.  j  a v a2  s .c  o m*/
 */
public RestJsonMapper() {
    super();

    this.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    this.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    this.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);

    this.setDateFormat(new Iso8601AndOthersDateFormat());

    SimpleModule testModule = new SimpleModule("jsr310",
            new Version(1, 0, 0, "", "be.wegenenverkeer.common", "common-resteasy"));
    testModule.addDeserializer(LocalDate.class, new LocalDateDeserializer());
    testModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer());
    testModule.addSerializer(LocalDate.class, new LocalDateSerializer());
    testModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer());
    this.registerModule(testModule);

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    if (null == classLoader) {
        classLoader = this.getClass().getClassLoader();
    }
    try {
        Class clazz = classLoader.loadClass("com.fasterxml.jackson.datatype.joda.JodaModule");
        Object instance = clazz.newInstance();
        this.registerModule((Module) instance);
    } catch (Exception ex) {
        // ignore, we do not require joda-time, but inform the user
        LOG.warn("Add jackson-datatype-joda dependency for joda-time support.");
    }
}

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);//from w w  w .  j  a  va2  s  . c  om

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

From source file:jp.classmethod.aws.brian.utils.BrianServerObjectMapperFactoryBean.java

@Override
protected ObjectMapper createInstance() {
    ObjectMapper mapper = new ObjectMapper();
    SimpleModule brianModule = new SimpleModule("brianServerModule", VERSION);
    brianModule.addSerializer(Trigger.class, new TriggerSerializer());
    mapper.registerModule(brianModule);//from   www .  ja va 2 s.c o  m
    mapper.registerModule(new Jdk8Module());

    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    df.setTimeZone(TimeZones.UNIVERSAL);
    mapper.setDateFormat(df);

    return mapper;
}

From source file:org.apache.airavata.db.ModelConversionHelper.java

/**
 * Private method to register the custom serializers and deserializers
 *///  w w w .j av  a  2s  .  co m
private void init() {
    this.objectMapper = new ObjectMapper();
    SimpleModule module = new SimpleModule("UserProfileService", new Version(1, 0, 0, null, null, null));

    module.addSerializer(UserProfile.class, new UserProfileSerializer());
    module.addDeserializer(UserProfile.class, new UserProfileDeserializer());

    module.addSerializer(Publication.class, new PublicationSerializer());
    module.addDeserializer(Publication.class, new PublicationDeserializer());

    module.addSerializer(Institution.class, new InstitutionSerializer());
    module.addDeserializer(Institution.class, new InstitutionDeserializer());

    objectMapper.registerModule(module);
}

From source file:fr.norad.jmxzabbix.core.ZabbixClient.java

public ZabbixClient(ZabbixConfig config) {
    this.config = config;

    // zabbix does not understand boolean with value true without quotes which is default of jackson
    SimpleModule module = new SimpleModule("BooleanAsString", new Version(1, 0, 0, null, null, null));
    module.addSerializer(new NonTypedScalarSerializerBase<Boolean>(Boolean.class) {
        @Override//from   ww  w  .j a va 2 s  .  c  o  m
        public void serialize(Boolean value, JsonGenerator jgen, SerializerProvider provider)
                throws IOException {
            jgen.writeString(value.toString());
        }
    });

    mapper.registerModule(module);
}

From source file:gaffer.serialisation.json.hyperloglogplus.HyperLogLogPlusJsonSerialisationTest.java

@Before
public void before() {
    mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);

    final SimpleModule module = new SimpleModule(
            HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SERIALISER_MODULE_NAME, new Version(1, 0, 0, null));
    module.addSerializer(HyperLogLogPlus.class, new HyperLogLogPlusJsonSerialiser());
    module.addDeserializer(HyperLogLogPlus.class, new HyperLogLogPlusJsonDeserialiser());

    mapper.registerModule(module);/*from   w  w w  .java  2s .  c o m*/
}

From source file:org.osiam.addons.selfadministration.util.UserObjectMapper.java

/**
 * Building jackson's object mapper and register a module with a default deserializer for scim user with extensions.
 *//*  w  w w  .ja  va2s. c  o  m*/
public UserObjectMapper() {
    super();
    SimpleModule userDeserializerModule = new SimpleModule("userDeserializerModule", Version.unknownVersion())
            .addDeserializer(User.class, new UserDeserializer(User.class));
    registerModule(userDeserializerModule);
}

From source file:org.pentaho.metaverse.impl.model.kettle.json.KettleObjectMapper.java

public KettleObjectMapper(List<StdSerializer> serializers, List<StdDeserializer> deserializers) {
    mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.enable(SerializationFeature.WRAP_EXCEPTIONS);

    transModule = new SimpleModule("PDIModule", new Version(1, 0, 0, null));

    if (!CollectionUtils.isEmpty(serializers)) {
        for (StdSerializer serializer : serializers) {
            transModule.addSerializer(serializer);
        }//  w w w  . jav  a  2 s.  co m
    }

    if (!CollectionUtils.isEmpty(deserializers)) {
        for (StdDeserializer deserializer : deserializers) {
            transModule.addDeserializer(deserializer.getValueClass(), deserializer);
        }
    }

    mapper.registerModule(transModule);
}

From source file:com.mastfrog.jackson.OptionalSerializer.java

@Override
public ObjectMapper configure(ObjectMapper mapper) {
    SimpleModule sm = new SimpleModule("optional", new Version(1, 0, 0, null, "com.mastfrog", "jackson"));
    sm.addSerializer(new OptionalSer());
    sm.addSerializer(new ReflectionOptionalSerializer());
    mapper.registerModule(sm);/*from   w  w w  .  j a  v a  2  s .  co m*/
    return mapper;
}

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   www . j a va  2  s  . c o  m
}