-
-
Notifications
You must be signed in to change notification settings - Fork 14
Mappers registry
Ahmad K. Bawaneh edited this page Sep 11, 2021
·
2 revisions
In some cases, user of the library might need to have a place to store all generated mappers and load/use them dynamically.
domino-jackson allows this kind of mapper registration to happen automatically through some code generation and allows to lookup the mapper using the pojo full class, this feature is called JSONRegistration.
to use JSONRegistration you need to annotate a package-info class with @JSONRegistration
like the following example :
@JSONRegistration("SomeName")
package com.foo.bar;
import org.dominokit.jacksonapt.annotation.JSONRegistration;
this will generate a class that register all generated mappers accessible to this package.
use the registration as the following :
assume 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>>> {}
you get the mappers from the registry like this :
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)){}){});