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:org.jongo.marshall.jackson.JacksonProcessor.java

public static ObjectMapper createPreConfiguredMapper() {
    ObjectMapper mapper = new ObjectMapper();
    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));

    SimpleModule module = new SimpleModule("jongo", new Version(1, 0, 0, null, null, null));
    addBSONTypeSerializers(module);/*ww  w .j  a  v a2s . co  m*/
    mapper.registerModule(module);
    return mapper;
}

From source file:org.mango.marshall.jackson.JacksonProcessor.java

public static ObjectMapper createPreConfiguredMapper() {
    ObjectMapper mapper = new ObjectMapper();
    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));

    SimpleModule module = new SimpleModule("mango", new Version(1, 0, 0, null, null, null));
    addBSONTypeSerializers(module);/*from  w w w . j a  v  a 2 s .  c  om*/
    mapper.registerModule(module);
    return mapper;
}

From source file:org.thingsplode.synapse.serializers.jackson.JacksonSerializer.java

private JacksonSerializer() {
    mapper = new ObjectMapper();
    module = new SimpleModule("CustomModule",
            new com.fasterxml.jackson.core.Version(1, 0, 0, null, null, null));
    //module.addDeserializer(ParameterWrapper.class, new ParameterWrapperDeserializer(ParameterWrapper.class));
    //mapper.registerModule(module);
}

From source file:com.ning.billing.recurly.model.RecurlyObject.java

public static XmlMapper newXmlMapper() {
    final XmlMapper xmlMapper = new XmlMapper();
    xmlMapper.setSerializerProvider(new RecurlyXmlSerializerProvider());
    final AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
    final AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
    final AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary);
    xmlMapper.setAnnotationIntrospector(pair);
    xmlMapper.registerModule(new JodaModule());
    xmlMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

    final SimpleModule m = new SimpleModule("module", new Version(1, 0, 0, null, null, null));
    m.addSerializer(Accounts.class, new RecurlyObjectsSerializer<Accounts, Account>(Accounts.class, "account"));
    m.addSerializer(AddOns.class, new RecurlyObjectsSerializer<AddOns, AddOn>(AddOns.class, "add_on"));
    m.addSerializer(Adjustments.class,
            new RecurlyObjectsSerializer<Adjustments, Adjustment>(Adjustments.class, "adjustment"));
    m.addSerializer(Coupons.class, new RecurlyObjectsSerializer<Coupons, Coupon>(Coupons.class, "coupon"));
    m.addSerializer(Invoices.class, new RecurlyObjectsSerializer<Invoices, Invoice>(Invoices.class, "invoice"));
    m.addSerializer(Plans.class, new RecurlyObjectsSerializer<Plans, Plan>(Plans.class, "plan"));
    m.addSerializer(RecurlyErrors.class,
            new RecurlyObjectsSerializer<RecurlyErrors, RecurlyError>(RecurlyErrors.class, "error"));
    m.addSerializer(SubscriptionAddOns.class,
            new RecurlyObjectsSerializer<SubscriptionAddOns, SubscriptionAddOn>(SubscriptionAddOns.class,
                    "subscription_add_on"));
    m.addSerializer(Subscriptions.class,
            new RecurlyObjectsSerializer<Subscriptions, Subscription>(Subscriptions.class, "subscription"));
    m.addSerializer(Transactions.class,
            new RecurlyObjectsSerializer<Transactions, Transaction>(Transactions.class, "transaction"));
    xmlMapper.registerModule(m);//from   w  ww  . java 2  s .c om

    return xmlMapper;
}

From source file:org.craftercms.social.util.serialization.UGCObjectMapper.java

protected void registerSerializationModule() {
    SimpleModule module = new SimpleModule("UGCSerializationModule", new Version(1, 0, 0, null, null, null));

    for (JsonSerializer ser : serializerList) {
        module.addSerializer(ser);/*from ww w. j a v  a  2 s .co m*/
    }

    for (Class key : deserializerMap.keySet()) {
        JsonDeserializer deser = deserializerMap.get(key);
        module.addDeserializer(key, deser);
    }

    registerModule(module);

}

From source file:org.osiam.configuration.JacksonConfig.java

private Module jacksonUserDeserializerModule() {
    return new SimpleModule("userDeserializerModule", new Version(1, 0, 0, null, "org.osiam", "osiam"))
            .addDeserializer(User.class, new UserDeserializer(User.SCHEMA));
}

From source file:org.osiam.resources.helper.JsonInputValidator.java

public JsonInputValidator() {

    ObjectMapper mapper = new ObjectMapper();
    SimpleModule testModule = new SimpleModule("userDeserializerModule",
            new Version(1, 0, 0, null, "org.osiam", "scim-schema")).addDeserializer(User.class,
                    new UserDeserializer(User.class));
    mapper.registerModule(testModule);/*from w  ww . jav  a2 s.c o m*/

    validators = new HashMap<>();
    validators.put(RequestMethod.PATCH, new PatchValidator(mapper));
    validators.put(RequestMethod.POST, new PostValidator(mapper));
    validators.put(RequestMethod.PUT, new PutValidator(mapper));
}

From source file:gaffer.jsonserialisation.JSONSerialiser.java

/**
 * Constructs a <code>JSONSerialiser</code> that skips nulls and default values and adds the custom serialisers.
 *
 * @param customTypeSerialisers custom type {@link com.fasterxml.jackson.databind.JsonSerializer}
 *//*  w ww .j a  va  2  s  .c  om*/
public JSONSerialiser(final JsonSerializer... customTypeSerialisers) {
    this();
    final SimpleModule module = new SimpleModule("custom", new Version(1, 0, 0, null, null, null));
    for (JsonSerializer customTypeSerialiser : customTypeSerialisers) {
        module.addSerializer(customTypeSerialiser);
    }
    mapper.registerModule(module);
}

From source file:com.barchart.netty.rest.client.RestClientBase.java

public RestClientBase(final String baseUrl_, final RestTransport transport_) {

    mapper = new ObjectMapper();
    module = new SimpleModule("json", Version.unknownVersion());

    transport = transport_;/*  w w  w. j a  v a 2  s.  c  o m*/
    baseUrl = baseUrl_;

}

From source file:org.rapidoid.db.impl.inmem.JacksonEntitySerializer.java

@SuppressWarnings("rawtypes")
private void initDbMapper() {
    SimpleModule dbModule = new SimpleModule("DbModule", new Version(1, 0, 0, null, null, null));

    dbModule.addDeserializer(DbList.class, new JsonDeserializer<DbList>() {
        @SuppressWarnings("unchecked")
        @Override//from  w  w w .j  av  a2  s .c o m
        public DbList deserialize(JsonParser jp, DeserializationContext ctxt)
                throws IOException, JsonProcessingException {
            Map<String, Object> data = jp.readValueAs(Map.class);
            String relation = (String) data.get("relation");
            List<? extends Number> ids = (List<Number>) data.get("ids");
            return new InMemDbList(db, null, relation, ids);
        }
    });

    dbModule.addDeserializer(DbSet.class, new JsonDeserializer<DbSet>() {
        @SuppressWarnings("unchecked")
        @Override
        public DbSet deserialize(JsonParser jp, DeserializationContext ctxt)
                throws IOException, JsonProcessingException {
            Map<String, Object> data = jp.readValueAs(Map.class);
            String relation = (String) data.get("relation");
            List<? extends Number> ids = (List<Number>) data.get("ids");
            return new InMemDbSet(db, null, relation, ids);
        }
    });

    dbModule.addDeserializer(DbRef.class, new JsonDeserializer<DbRef>() {
        @SuppressWarnings("unchecked")
        @Override
        public DbRef deserialize(JsonParser jp, DeserializationContext ctxt)
                throws IOException, JsonProcessingException {
            Map<String, Object> data = jp.readValueAs(Map.class);
            String relation = (String) data.get("relation");
            List<? extends Number> ids = (List<Number>) data.get("ids");
            U.must(ids.size() <= 1, "Expected 0 or 1 IDs!");
            long id = !ids.isEmpty() ? ids.get(0).longValue() : -1;
            return new InMemDbRef(db, null, relation, id);
        }
    });

    mapper.registerModule(dbModule);

    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}