All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fasterxml.jackson.module.osgi.OsgiJacksonModule Maven / Gradle / Ivy

There is a newer version: 2.18.1
Show newest version
package com.fasterxml.jackson.module.osgi;

import org.osgi.framework.BundleContext;

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * A Jackson Module to inject OSGI services in deserialized objects.
 * Note that registration will replace possibly exsting value injector
 * ({@link com.fasterxml.jackson.databind.InjectableValues}) implementation
 * by calling {@link ObjectMapper#setInjectableValues}.
 *
 * @see OsgiInjectableValues
 */
public class OsgiJacksonModule extends Module
{
    private final BundleContext bundleContext;

    public OsgiJacksonModule(BundleContext bundleContext)
    {
        this.bundleContext = bundleContext;
    }
    
    @Override
    public String getModuleName() {
        return getClass().getSimpleName();
    }

    @Override
    public Version version() {
        return PackageVersion.VERSION;
    }

    @Override
    public void setupModule(SetupContext context)
    {
        ObjectMapper mapper = context.getOwner();
        mapper.setInjectableValues(new OsgiInjectableValues(bundleContext));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy