-
-
Notifications
You must be signed in to change notification settings - Fork 14
Define the mapper
Domino-jackson provide various options when it comes to how you define the mappers for a pojo class:
- You have direct access to the pojo source code:
if you can edit the source code of the pojo class you can simply annotate the pojo class as JSONMapper
and this will generate the mapper and the (de)serializers of the pojo in the same package of the pojo, this is very useful when you have the pojo as part of your current project source code or you want to ship the mappers with the pojo.
JSONMapper
will generate both deserializers and serializers for your pojo, but sometimes you might only need to read a JSON but you dont write it, or you only need to write JSON but dont need to read it, in this case we provide 2 more annotation JSONReader
to generate the deserializers only ,and JSONWriter
to generate the serializers only.
- You dont have access to the pojo source code, or you dont want to clutter the pojo with extra annotations, or you dont want your pojo to have dependency on domino-jackson:
In this case you can define the mapper externally from your pojo by introducing a new marker interface, e.g:
@JSONMapper
interface PersonMapper extends ObjectMapper<Person>{}
this will generate the mapper in the same package as the interface and will use the interface as a base name, in this case the generated mapper is PersonMapperImpl
.
to generate a reader only use
@JSONReader
interface PersonReader extends ObjectReader<Person>{}
and to generate a writer only use
@JSONWriter
interface PersonWriter extends ObjectWriter<Person>{}
- You are generating a mapper for something that is not a bean, e.g :
HashMap<String, List<String>>
in this case you can use the interface style to generate such mappers
@JSONMapper
interface SomeHashMapMapper extends ObjectMapper<HashMap<String, List<String>>>{}
this applies to any datatype supported by the lib.