Create custom annotation that uses @JsonIgnore based on value in superclass

11 Views Asked by At

I need to create a new annotation which is used to ignore a field in the output JSON file when the property value is stored in a map in the superclass

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR,   ElementType.FIELD})
public @interface MyJsonIgnore {
    boolean value() default true;
}

/

public class Qdt extends BaseDTO {
@MyJsonIgnore
public String getName()
{
    return get( "name" );
}
public void setName( String name )
{
    set( "name", name );
}

Here I need jackson to ignore the property when it's in the map.

public class BaseDTO implements Serializable {
    private HashMap<String,Object> map;

    public Object get(String key){
        return map.get(key);
    }
    public void set(String key, Object value){
        map.put(key, value);
    }
}
0

There are 0 best solutions below