Skip to content

Generics

Ahmad K. Bawaneh edited this page Dec 24, 2019 · 1 revision

Generics

Domino-jackson can process generics types as long as the type information are available for the processor for example

assume you have the following base generic pojo

public abstract class BaseGenericType<T, V> {

    private T field1;
    private V field2;

    public T getField1() {
        return field1;
    }

    public void setField1(T field1) {
        this.field1 = field1;
    }

    public V getField2() {
        return field2;
    }

    public void setField2(V field2) {
        this.field2 = field2;
    }
}

now a child class can extend that class and provide the type information

@JSONMapper
public class SampleGenericType extends BaseGenericType<String, Integer> {

    private String field3;

    public String getField3() {
        return field3;
    }

    public void setField3(String field3) {
        this.field3 = field3;
    }
}

Now domino-jackson will generate a mapper for this pojo and will use the correct String and Integer types for field1 and field2 from the base class.

notice that annotating the Base class with JSONMapper wont work, as the type information is not available for the processor.

defining the mapper using an interface like this should work

@JSONMapper
interface GenericMapper extend ObjectMapper<BaseGenericType<T, V>>{}