Skip to content

lib-jsonserialiser

library

Type-discriminated JSONL deserialiser. Each line is a JSON object with a @type field that names the target class; the deserialiser instantiates the right type from a registered class lookup table.

<dependency>
    <groupId>com.telamin</groupId>
    <artifactId>lib-jsonserialiser</artifactId>
    <version>1.0.35</version>
</dependency>

When to use

  • A file or socket feed carries multiple event types as JSONL.
  • You want strongly-typed events in your processor without a custom mapper per feed.

Sample

Input file trades.jsonl:

{"@type":"Trade","symbol":"AAPL","qty":100,"price":150.25}
{"@type":"Quote","symbol":"AAPL","bid":150.20,"ask":150.30}
{"@type":"Trade","symbol":"GOOG","qty":50,"price":2700.50}

Wire it into a file feed:

eventFeeds:
  - name: trades
    instance: !!com.telamin.mongoose.plugin.connector.file.FileEventSource
      filename: ./data-in/trades.jsonl
    valueMapper: !!com.telamin.mongoose.plugin.lib.json.TypeSerialiser
      typeMap:
        Trade: com.example.Trade
        Quote: com.example.Quote

Now your processor receives instances of Trade and Quote directly:

public class TradeHandler extends ObjectEventHandlerNode {
    @Override
    protected boolean handleEvent(Object event) {
        return switch (event) {
            case Trade t -> { handleTrade(t); yield true; }
            case Quote q -> { handleQuote(q); yield true; }
            default -> false;
        };
    }
}

Configuration reference

Field Default Notes
typeMap empty Map<String, Class<?>> mapping @type values to classes.

Operational notes

  • Backed by Jackson — extend with custom deserializers / modules by subclassing.
  • Unknown @type values are logged and the line is skipped (does not throw).
  • Each entry in typeMap must be a real class on the classpath; misspellings throw at startup.

Examples

Source

mongoose-plugins/library/lib-jsonserialiser