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

Source Link

Document

Constructors that should only be used for non-reusable convenience modules used by app code: "real" modules should use actual name and version number information.

Usage

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);//from   w  w  w.ja  v a 2s.c o  m

    return builder;
}

From source file:com.reprezen.swagedit.model.Model.java

protected static ObjectMapper createMapper() {
    final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    final SimpleModule module = new SimpleModule();
    module.addDeserializer(AbstractNode.class, new NodeDeserializer());
    mapper.registerModule(module);/* w ww  .  j  a v a  2  s  . c om*/
    return mapper;
}

From source file:ws.doerr.httpserver.Server.java

private void intStart(String packages) throws Exception {
    // Set up Jackson
    mapper = new ObjectMapper();
    mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
            .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)
            .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE));

    JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
    provider.setMapper(mapper);//w ww . jav  a2  s. c o  m

    SimpleModule module = new SimpleModule();
    module.addSerializer(Path.class, new PathSerializer());
    mapper.registerModule(module);

    ResourceConfig resourceConfig = new ResourceConfig().packages(packages).register(provider);

    ServerConfiguration cfg = Configuration.get(ServerConfiguration.class);
    server = GrizzlyHttpServerFactory.createHttpServer(cfg.getServerUri(), resourceConfig, false);

    // Handle the static content
    // Override onMissingResource for SPA
    HttpHandler httpHandler;
    if (Configuration.isDebug()) {
        // If we're in debug mode, serve the content from the folder. This
        // allows you to live edit the static content without having to
        // restart the server every time.
        httpHandler = new StaticHttpHandler("src/main/resources/web", "");
        server.getListener("grizzly").getFileCache().setEnabled(false);
    } else {
        // Normal run, serve the content from the jar file
        httpHandler = new CLStaticHttpHandler(Server.class.getClassLoader(), "/web/build/");
    }
    server.getServerConfiguration().addHttpHandler(httpHandler, "/");

    // Configure the WebSocket handler
    WebSocketAddOn webSocket = new WebSocketAddOn();
    server.getListener("grizzly").registerAddOn(webSocket);
    app = new WebSocketApp();

    server.start();

    LOG.log(Level.INFO, "Server running on http://{0}:{1,number,#}", new Object[] { cfg.hostname, cfg.port });
}

From source file:org.resthub.web.converter.MappingJackson2JsonHttpMessageConverter.java

/**
 * Construct a new {@code BindingJacksonHttpMessageConverter}.
 *//*from   www .j a va  2 s. c  o  m*/
public MappingJackson2JsonHttpMessageConverter() {
    super(new MediaType("application", "json", DEFAULT_CHARSET));
    objectMapper = new ObjectMapper();
    SimpleModule module = new SimpleModule();
    module.addAbstractTypeMapping(Page.class, PageResponse.class);
    objectMapper.registerModule(module);
    AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
    objectMapper.setAnnotationIntrospector(introspector);
    objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

}

From source file:org.venice.beachfront.bfapi.services.OAuthServiceTests.java

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    SimpleModule module = new SimpleModule();
    module.addDeserializer(AbstractStringList.class, new AbstractStringList.Deserializer());
    this.objectMapper.registerModule(module);

    ReflectionTestUtils.setField(this.oauthService, "domain", "test.localdomain");
    ReflectionTestUtils.setField(this.oauthService, "oauthTokenUrl", this.oauthTokenUrl);
    ReflectionTestUtils.setField(this.oauthService, "redirectUrl", this.redirectUrl);
    ReflectionTestUtils.setField(this.oauthService, "oauthProfileUrl", this.oauthProfileUrl);
    ReflectionTestUtils.setField(this.oauthService, "oauthClientId", this.oauthClientId);
    ReflectionTestUtils.setField(this.oauthService, "oauthClientSecret", this.oauthClientSecret);
    ReflectionTestUtils.setField(this.oauthService, "oauthResponseLogOnError", false);
}

From source file:org.apache.james.mailbox.tika.TikaTextExtractor.java

private ObjectMapper initializeObjectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    SimpleModule mapModule = new SimpleModule();
    mapModule.addDeserializer(ContentAndMetadata.class, new ContentAndMetadataDeserializer());
    objectMapper.registerModule(mapModule);
    return objectMapper;
}

From source file:com.arpnetworking.clusteraggregator.http.Routes.java

/**
 * Public constructor.//from   w  w w  . jav a 2 s .  c o m
 *
 * @param actorSystem Instance of <code>ActorSystem</code>.
 * @param metricsFactory Instance of <code>MetricsFactory</code>.
 * @param healthCheckPath The path for the health check.
 * @param statusPath The path for the status.
 */
public Routes(final ActorSystem actorSystem, final MetricsFactory metricsFactory, final String healthCheckPath,
        final String statusPath) {
    _actorSystem = actorSystem;
    _metricsFactory = metricsFactory;
    _healthCheckPath = healthCheckPath;
    _statusPath = statusPath;

    _objectMapper = ObjectMapperFactory.createInstance();
    _objectMapper.registerModule(new SimpleModule().addSerializer(Member.class, new MemberSerializer()));
    _objectMapper.registerModule(new AkkaModule(actorSystem));
}

From source file:org.opendaylight.sxp.csit.libraries.DeviceTestLibrary.java

/**
 * @param libraryServer Server where Library will be added
 *//*from   ww w .j  a v  a 2s .c o m*/
public DeviceTestLibrary(RobotLibraryServer libraryServer) {
    super(libraryServer);
    connectionTimers.setReconciliationTime(0);
    connectionTimers.setDeleteHoldDownTime(0);
    pojoBindingsSerializer.registerModule(
            new SimpleModule().addSerializer(SxpBindingFields.class, new JsonSerializer<SxpBindingFields>() {

                @Override
                public void serialize(SxpBindingFields value, JsonGenerator jgen, SerializerProvider provider)
                        throws IOException {
                    jgen.writeStartObject();
                    jgen.writeNumberField("sgt", value.getSecurityGroupTag().getValue());
                    jgen.writeArrayFieldStart("ip-prefix");
                    jgen.writeString(new String(value.getIpPrefix().getValue()));
                    jgen.writeEndArray();
                    jgen.writeEndObject();
                }
            }));
}

From source file:org.resthub.web.converter.MappingJackson2XmlHttpMessageConverter.java

/**
 * Construct a new {@code BindingJacksonHttpMessageConverter}.
 *///from   ww  w. j  a  va  2 s.co  m
public MappingJackson2XmlHttpMessageConverter() {
    super(new MediaType("application", "xml", DEFAULT_CHARSET));
    JacksonXmlModule xmlModule = new JacksonXmlModule();
    xmlModule.setDefaultUseWrapper(false);
    objectMapper = new XmlMapper(xmlModule);
    SimpleModule module = new SimpleModule();
    module.addAbstractTypeMapping(Page.class, PageResponse.class);
    objectMapper.registerModule(module);
    AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
    objectMapper.setAnnotationIntrospector(introspector);
}

From source file:com.streamsets.datacollector.record.io.TestFieldAttributeCompatibility.java

/**
 * Essentially the same as {@link com.streamsets.datacollector.json.ObjectMapperFactory#create(boolean)},
 * but using the previous implementation of {@link com.streamsets.datacollector.record.FieldDeserializer}
 *
 * @return the ObjectMapper//w  w w.j a  v  a  2 s.  c o  m
 */
private static ObjectMapper createNonAttributeObjectMapper() {
    ObjectMapper objectMapper = MetricsObjectMapperFactory.create(false);
    SimpleModule module = new SimpleModule();
    module.addDeserializer(FieldJson.class, new PreAttributesFieldDeserializer());
    module.addDeserializer(ErrorMessage.class, new ErrorMessageDeserializer());
    objectMapper.registerModule(module);
    return objectMapper;
}