Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.introspect;
  
  
  
Interface for object used for determine which property elements (methods, fields, constructors) can be auto-detected, with respect to their visibility modifiers.

Note on type declaration: funky recursive type is necessary to support builder/fluent pattern.

Author(s):
tatu
 
 public interface VisibilityChecker<T extends VisibilityChecker<T>>
 {
     // // Builder methods
 
    
Builder method that will return an instance that has same settings as this instance has, except for values that given annotation overrides.
 
     public T with(JsonAutoDetect ann);

    
Builder method that will create and return an instance that has specified com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility value to use for all property elements. Typical usage would be something like:
  mapper.setVisibilityChecker(
     mapper.getVisibilityChecker().with(Visibility.NONE));
(which would basically disable all auto-detection)
 
     public T with(Visibility v);

    
Builder method that will create and return an instance that has specified com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility value to use for specified property. Typical usage would be:
  mapper.setVisibilityChecker(
     mapper.getVisibilityChecker().withVisibility(JsonMethod.FIELD, Visibility.ANY));
(which would basically enable auto-detection for all member fields)
 
     public T withVisibility(PropertyAccessor methodVisibility v);
    
    
Builder method that will return a checker instance that has specified minimum visibility level for regular ("getXxx") getters.
 
     public T withGetterVisibility(Visibility v);

    
Builder method that will return a checker instance that has specified minimum visibility level for "is-getters" ("isXxx").
 
     public T withIsGetterVisibility(Visibility v);
    
    
Builder method that will return a checker instance that has specified minimum visibility level for setters.
 
     public T withSetterVisibility(Visibility v);

    
Builder method that will return a checker instance that has specified minimum visibility level for creator methods (constructors, factory methods)
 
     public T withCreatorVisibility(Visibility v);

    
Builder method that will return a checker instance that has specified minimum visibility level for fields.
 
     public T withFieldVisibility(Visibility v);
 	
     // // Accessors
 	
    
Method for checking whether given method is auto-detectable as regular getter, with respect to its visibility (not considering method signature or name, just visibility)
 
     public boolean isGetterVisible(Method m);
     public boolean isGetterVisible(AnnotatedMethod m);

    
Method for checking whether given method is auto-detectable as is-getter, with respect to its visibility (not considering method signature or name, just visibility)
    public boolean isIsGetterVisible(Method m);
    public boolean isIsGetterVisible(AnnotatedMethod m);
    
    
Method for checking whether given method is auto-detectable as setter, with respect to its visibility (not considering method signature or name, just visibility)
    public boolean isSetterVisible(Method m);
    public boolean isSetterVisible(AnnotatedMethod m);

    
Method for checking whether given method is auto-detectable as Creator, with respect to its visibility (not considering method signature or name, just visibility)
    public boolean isCreatorVisible(Member m);
    public boolean isCreatorVisible(AnnotatedMember m);

    
Method for checking whether given field is auto-detectable as property, with respect to its visibility (not considering method signature or name, just visibility)
    public boolean isFieldVisible(Field f);
    public boolean isFieldVisible(AnnotatedField f);
    /*
    /********************************************************
    /* Standard implementation suitable for basic use
    /********************************************************
    */

   
Default standard implementation is purely based on visibility modifier of given class members, and its configured minimum levels. Implemented using "builder" (aka "Fluid") pattern, whereas instances are immutable, and configuration is achieved by chainable factory methods. As a result, type is declared is funky recursive generic type, to allow for sub-classing of build methods with property type co-variance.

Note on JsonAutoDetect annotation: it is used to access default minimum visibility access definitions.

        getterVisibility = .,
        isGetterVisibility = .,
        setterVisibility = .,
        
By default, all matching single-arg constructed are found, regardless of visibility. Does not apply to factory methods, they can not be auto-detected; ditto for multiple-argument constructors.
        creatorVisibility = .,
        fieldVisibility = .
    )
    public static class Std
        implements VisibilityChecker<Std>,
            java.io.Serializable
    {
        private static final long serialVersionUID = -7073939237187922755L;

        
This is the canonical base instance, configured with default visibility values
        protected final static Std DEFAULT = new Std(Std.class.getAnnotation(JsonAutoDetect.class));
        
        protected final Visibility _getterMinLevel;
        protected final Visibility _isGetterMinLevel;
        protected final Visibility _setterMinLevel;
        protected final Visibility _creatorMinLevel;
        protected final Visibility _fieldMinLevel;
        public static Std defaultInstance() { return ; }
        
        
Constructor used for building instance that has minumum visibility levels as indicated by given annotation instance

Parameters:
ann Annotations to use for determining minimum visibility levels
	public Std(JsonAutoDetect ann)
	{
	    // let's combine checks for enabled/disabled, with minimimum level checks:
             = ann.isGetterVisibility();
             = ann.setterVisibility();
             = ann.creatorVisibility();
             = ann.fieldVisibility();
	}

Constructor that allows directly specifying minimum visibility levels to use
	public Std(Visibility getterVisibility isGetterVisibility setterVisibility creatorVisibility field)
        {
	     = getter;
	     = isGetter;
	     = setter;
	     = creator;
	     = field;
        }

Costructor that will assign given visibility value for all properties.

Parameters:
v level to use for all property types
        public Std(Visibility v)
        {
            // typically we shouldn't get this value; but let's handle it if we do:
            if (v == .) {
                 = .;
                 = .;
                 = .;
                 = .;
                 = .;
            } else {
                 = v;
                 = v;
                 = v;
                 = v;
                 = v;
            }
        }
	/*
        /********************************************************
	/* Builder/fluent methods for instantiating configured
	/* instances
	/********************************************************
	 */
//      @Override
	public Std with(JsonAutoDetect ann)
	{
            Std curr = this;
	    if (ann != null) {
    	    curr = curr.withGetterVisibility(ann.getterVisibility());
    	    curr = curr.withIsGetterVisibility(ann.isGetterVisibility());
                curr  = curr.withSetterVisibility(ann.setterVisibility());
                curr = curr.withCreatorVisibility(ann.creatorVisibility());
                curr = curr.withFieldVisibility(ann.fieldVisibility());
	    }
	    return curr;
	}
//      @Override
	public Std with(Visibility v)
	{
	    if (v == .) {
	        return ;
	    }
	    return new Std(v);
	}
//      @Override
	{
	    switch (method) {
	    case :
	        return withGetterVisibility(v);
	    case :
	        return withSetterVisibility(v);
	    case :
	        return withCreatorVisibility(v);
	    case :
	        return withFieldVisibility(v);
	    case :
	        return withIsGetterVisibility(v);
            case :
                return with(v);
            //case NONE:
            // break;
	    }
            return this;
	}
//      @Override
	    if (v == .)  v = .;
            if ( == vreturn this;
	}
//      @Override
        public Std withIsGetterVisibility(Visibility v) {
            if (v == .)  v = .;
            if ( == vreturn this;
            return new Std(v);
        }
//      @Override
            if (v == .)  v = .;
            if ( == vreturn this;
            return new Std(v);
	}
//      @Override
            if (v == .)  v = .;
            if ( == vreturn this;
	}
//      @Override
            if (v == .)  v = .;
            if ( == vreturn this;
	}
        /*
        /********************************************************
        /* Public API impl
        /********************************************************
         */
//	@Override
	public boolean isCreatorVisible(Member m) {
	    return .isVisible(m);
    	}
    
//      @Override
    	public boolean isCreatorVisible(AnnotatedMember m) {
    	    return isCreatorVisible(m.getMember());
    	}
    
//      @Override
    	public boolean isFieldVisible(Field f) {
    	    return .isVisible(f);
    	}
    
//      @Override
    	public boolean isFieldVisible(AnnotatedField f) {
    	    return isFieldVisible(f.getAnnotated());
    	}
    
//      @Override
    	public boolean isGetterVisible(Method m) {
    	    return .isVisible(m);
    	}    
//      @Override
        public boolean isGetterVisible(AnnotatedMethod m) {
    	    return isGetterVisible(m.getAnnotated());
    	}
//      @Override
        public boolean isIsGetterVisible(Method m) {
            return .isVisible(m);
        }    
//      @Override
        public boolean isIsGetterVisible(AnnotatedMethod m) {
            return isIsGetterVisible(m.getAnnotated());
        }
//      @Override
        public boolean isSetterVisible(Method m) {
            return .isVisible(m);
        }
    
//      @Override
        public boolean isSetterVisible(AnnotatedMethod m) {
            return isSetterVisible(m.getAnnotated());
        }
        /*
        /********************************************************
        /* Standard methods
        /********************************************************
         */
        @Override
        public String toString() {
            return new StringBuilder("[Visibility:")
                .append(" getter: ").append()
                .append(", isGetter: ").append()
                .append(", setter: ").append()
                .append(", creator: ").append()
                .append(", field: ").append()
                .append("]").toString();
        }
    }
New to GrepCode? Check out our FAQ X