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:org.rgiskard.jackson.CustomObjectMapper.java

public CustomObjectMapper() {
    SimpleModule advisingModule = new SimpleModule("AdvisingModule");
    advisingModule.addSerializer(Module.class, new ModuleJsonSerializer());
    this.registerModule(advisingModule);
}

From source file:ijfx.service.overlay.io.OverlaySaver.java

public void save(List<? extends Overlay> overlays, File file) throws IOException {

    ObjectMapper mapper = new ObjectMapper();
    SimpleModule module = new SimpleModule();
    module.addSerializer(Overlay.class, new OverlaySerializer());
    mapper.registerModule(module);//www . ja  v  a  2  s. com

    mapper.writeValue(file, overlays);

}

From source file:org.moserp.common.json_schema.ObjectMapperBuilder.java

private void registerQuantitySerializer(ObjectMapper mapper) {
    SimpleModule module = new SimpleModule();
    module.addSerializer(Quantity.class, new BigDecimalWrapperSerializer());
    module.addSerializer(Price.class, new BigDecimalWrapperSerializer());
    mapper.registerModule(module);//from  www . j av  a2  s .  c  om
}

From source file:com.tilab.fiware.metaware.dao.impls.mongodb.core.CustomObjectMapper.java

/**
 * Custom ObjectMapper definition.// www . j  ava 2  s. co  m
 */
public CustomObjectMapper() {
    SimpleModule module = new SimpleModule("ObjectIdmodule");
    module.addSerializer(ObjectId.class, new ObjectIdSerializer()); // specify the custom ObjectId serializer
    this.registerModule(module);
}

From source file:com.arpnetworking.test.junitbenchmarks.GCShapshotSerializerTest.java

@Test
public void testSerialization() {
    final SimpleModule module = new SimpleModule();
    module.addSerializer(GCSnapshot.class, new GCSnapshotSerializer());
    final ObjectMapper mapper = ObjectMapperFactory.createInstance();
    mapper.registerModule(module);/*  w  w  w.java 2s .  c o m*/

    final GCSnapshot testSnapshot = DataCreator.createGCSnapshot();

    final JsonNode jsonNode = mapper.valueToTree(testSnapshot);
    Assert.assertTrue(jsonNode.isObject());
    Assert.assertThat(jsonNode.get("accumulatedInvocations").asLong(), Matchers.greaterThanOrEqualTo(0L));
    Assert.assertThat(jsonNode.get("accumulatedTime").asLong(), Matchers.greaterThanOrEqualTo(0L));
}

From source file:com.cloudera.exhibit.server.main.ExhibitApplication.java

void setupMapper(ObjectMapper mapper) {
    SimpleModule mod = new SimpleModule("exhibit", Version.unknownVersion());
    mod.addSerializer(Exhibit.class, new ExhibitSerializer());
    mod.addSerializer(Frame.class, new FrameSerializer());
    mapper.registerModule(mod);//  w  w w  .  j  a v  a  2s.  c  o m
}

From source file:org.moserp.common.rest.ObjectMapperCustomizer.java

private void registerQuantitySerializer(ObjectMapper mapper) {
    SimpleModule module = new SimpleModule();
    module.addSerializer(Quantity.class,
            new WithConverterSerializer<>(new BigDecimalWrapperToStringConverter()));
    module.addSerializer(Price.class, new WithConverterSerializer<>(new BigDecimalWrapperToStringConverter()));
    module.addSerializer(RestUri.class, new WithConverterSerializer<>(new RestUriToStringConverter()));
    mapper.registerModule(module);/* w  w  w .j a  va  2  s.  c  o m*/
}

From source file:com.siemens.sw360.portal.common.ThriftJsonSerializer.java

public ThriftJsonSerializer() {
    // Create a module with the proper serializer for Thrift classes
    SimpleModule module = new SimpleModule();
    module.addSerializer(TBase.class, new TBaseSerializer());

    // Create the object mapper and register the module
    mapper = new ObjectMapper();
    mapper.registerModule(module);//from   www . ja  v a 2  s  . c o  m
}

From source file:org.lambdamatic.internal.elasticsearch.codec.DocumentSearchCodec.java

/**
 * Constructor.//from w ww. j  ava  2  s.c om
 * 
 */
public DocumentSearchCodec() {
    this.objectMapper = new ObjectMapper();
    // custom serializers for queries
    final SimpleModule module = new SimpleModule();
    module.addSerializer(DocumentSearch.class, new DocumentSearchSerializer());
    module.addSerializer(TermQuery.class, new TermQuerySerializer());
    module.addSerializer(RangeQuery.class, new RangeQuerySerializer());
    module.addSerializer(MatchQuery.class, new MatchQuerySerializer());
    module.addSerializer(BooleanQuery.class, new BooleanQuerySerializer());
    module.addSerializer(GeoBoundingBoxQuery.class, new GeoBoundingBoxSerializer());
    this.objectMapper.registerModule(module);
    // support for Java time
    this.objectMapper.registerModule(new JavaTimeModule());
    // configure LocalDate serialization as string with pattern: YYYY-mm-dd
    this.objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);

}