1. Domino Jackson
  2. Mappers registry

Mappers registry

In some cases, You might need to store all generated mappers and load or use them dynamically.

Domino-jackson includes a mechanism that allows this kind of mapper registration to happen automatically through some code generation, then the registry can be used to look-up the mapper using the pojo full qualified type of the bean, this feature is called JSONRegistration.

to use JSONRegistration you need to annotate a package-info class with @JSONRegistration , example :

			@JSONRegistration("SomeName")
package com.foo.bar;

import org.dominokit.jacksonapt.annotation.JSONRegistration;
		

This will generate a class that register all generated mappers from all domino-jackson annotated beans in this package.

Use the registration as the following :

Assuming we have the above JSONRegistration and we have the following mappers

			@JSONMapper
public interface PersonMapper extends ObjectMapper<Person> {}

@JSONMapper
interface ListOfMapMapper extends ObjectMapper<List<Map<Integer, SimpleBeanObject>>> {}
		

Then the following example show how we can access those mappers dynamically :

			JsonRegistry testJsonRegistry = SomeNameJsonRegistry.getInstance();

testJsonRegistry.getMapper(TypeToken.of(Person.class));

testJsonRegistry.getMapper(
        	new TypeToken<List<Map<Integer, SimpleBeanObject>>>(
        		List.class,
        		new TypeToken<Map<Integer, SimpleBeanObject>>(
        			Map.class,
        			TypeToken.of(Integer.class),
        			TypeToken.of(SimpleBeanObject.class)){}){});
		

We are a group of passionate people who love what we do

Donate & Support Us