GithubHelp home page GithubHelp logo

valery1707 / jackson-module-osgi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fasterxml/jackson-module-osgi

0.0 3.0 0.0 66 KB

A Jackson module to inject OSGI services in deserialized objects.

Java 100.00%

jackson-module-osgi's Introduction

jackson-module-osgi

Maven Central Javadoc

This module provides a way to inject OSGI services into deserialized objects. Thanks to the JacksonInject annotations, the OsgiJacksonModule will search for the required service in the OSGI service registry and injects it in the object while deserializing.

Usage

For example, imagine a drawing software that persists shapes in JSON documents (on file system, mongodb or orientdb). The Shape object needs a DrawingService that is in charge of drawing shapes.

interface Drawable {
    void draw();
}

interface DrawingService {
    void draw(Drawable drawable);
}
	
class Shape implements Drawable {
    public int x;
    public int y;

    private DrawingService drawingService;

    public Shape(@JacksonInject DrawingService drawingService)
    {
        this.drawingService = drawingService;
    }

    @Override
    public void draw()
    {
        drawingService.draw(this);
    }
}

To deserialize shapes and to inject the drawing service :

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new OsgiJacksonModule(bundleContext));
Shape shape = mapper.reader().forType(Shape.class).readValue("{\"x\":13,\"y\":21}");

The module supports OSGI filters to select the service more accurately :

public Shape(@JacksonInject(value = "(provider=ACME)") DrawingService drawingService)
{
    this.drawingService = drawingService;
}

Limitations

  • injecting value in setter is not supported
  • dynamicity is not supported. If the service is unregistered, the deserialized object will keep the old service reference.

jackson-module-osgi's People

Contributors

cowtowncoder avatar gdelafosse avatar valery1707 avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.