1. Domino Jackson
  2. Getting started
  3. Defining mappers

Mapper Definition Options

Domino-jackson offers flexibility in how you define mappers for your POJO (Plain Old Java Object) classes:

  • Direct POJO Access:

    If you have access to the source code of your POJO class, you can easily generate mappers by annotating the class with JSONMapper. This approach automatically generates mappers and (de)serializers in the same package as your POJO. This is particularly handy when your POJO is part of your project's source code or when you want to ship the mappers alongside the POJO itself. JSONMapper> generates both deserializers and serializers for your POJO. However, there may be cases where you only need to read JSON without writing it, or vice versa. In such situations, you can utilize two additional annotations: JSONReader> for generating deserializers only and JSONWriter for generating serializers only.

  • External Mapper Definition:

    In scenarios where you cannot access the source code of the POJO, prefer not to clutter the POJO with additional annotations, or aim to keep your POJO free from dependencies on domino-jackson, an alternative approach is available. You can define the mapper externally by introducing a new marker interface:
    			@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>{}
    		
  • Generating mappers none bean types

    If you are generating a mapper for a data type that is not represented by a bean but rather with data structure types, for example HashMap<String, List<String>> you can utilize the interface style for this:

    			@JSONMapper
    interface SomeHashMapMapper extends ObjectMapper<HashMap<String, List<String>>>{}
    		

    And this applies to any datatype supported by the library.

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

Donate & Support Us