Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.introspect;
  
  
Object that represents non-static (and usually non-transient/volatile) fields of a class.
 
 public final class AnnotatedField
     extends AnnotatedMember
     implements java.io.Serializable
 {
     private static final long serialVersionUID = 7364428299211355871L;

    
Actual java.lang.reflect.Field used for access.

Transient since it can not be persisted directly using JDK serialization

 
     protected final transient Field _field;

    
Temporary field required for JDK serialization support
 
     protected Serialization _serialization;
     
     /*
     /**********************************************************
     /* Life-cycle
     /**********************************************************
      */
 
     public AnnotatedField(Field fieldAnnotationMap annMap)
     {
         super(annMap);
          = field;
     }
     
     @Override
     public AnnotatedField withAnnotations(AnnotationMap ann) {
         return new AnnotatedField(ann);
     }

    
Method used for JDK serialization support
 
     protected AnnotatedField(Serialization ser)
     {
         super(null);
          = null;
          = ser;
     }
     
     /*
     /**********************************************************
     /* Annotated impl
     /**********************************************************
      */
 
     @Override
     public Field getAnnotated() { return ; }
 
     @Override
     public int getModifiers() { return .getModifiers(); }
 
     @Override
     public String getName() { return .getName(); }
 
     @Override
     public <A extends Annotation> A getAnnotation(Class<A> acls)
     {
         return ( == null) ? null : .get(acls);
     }
 
     @Override
     public Type getGenericType() {
         return .getGenericType();
     }
 
     @Override
     public Class<?> getRawType() {
         return .getType();
     }
     
     /*
     /**********************************************************
     /* AnnotatedMember impl
     /**********************************************************
      */
 
     @Override
     public Class<?> getDeclaringClass() { return .getDeclaringClass(); }
 
    @Override
    public Member getMember() { return ; }
    @Override
    public void setValue(Object pojoObject valuethrows IllegalArgumentException
    {
        try {
            .set(pojovalue);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Failed to setValue() for field "
                    +getFullName()+": "+e.getMessage(), e);
        }
    }
    @Override
    public Object getValue(Object pojothrows IllegalArgumentException
    {
        try {
            return .get(pojo);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Failed to getValue() for field "
                    +getFullName()+": "+e.getMessage(), e);
        }
    }
    
    /*
    /**********************************************************
    /* Extended API, generic
    /**********************************************************
     */
    public String getFullName() {
        return getDeclaringClass().getName() + "#" + getName();
    }
    public int getAnnotationCount() { return .size(); }
    @Override
    public String toString()
    {
        return "[field "+getFullName()+"]";
    }
    /*
    /**********************************************************
    /* JDK serialization handling
    /**********************************************************
     */
    Object writeReplace() {
        return new AnnotatedField(new Serialization());
    }
    Object readResolve() {
        Class<?> clazz = .;
        try {
            Field f = clazz.getDeclaredField(.);
            // 06-Oct-2012, tatu: Has "lost" its security override, may need to force back
            if (!f.isAccessible()) {
                ClassUtil.checkAndFixAccess(f);
            }
            return new AnnotatedField(fnull);
        } catch (Exception e) {
            throw new IllegalArgumentException("Could not find method '"+.
                        +"' from Class '"+clazz.getName());
        }
    }
    
    
Helper class that is used as the workaround to persist Field references. It basically just stores declaring class and field name.
    private final static class Serialization
        implements java.io.Serializable
    {
        private static final long serialVersionUID = 1L;
        protected Class<?> clazz;
        protected String name;
        public Serialization(Field f) {
             = f.getDeclaringClass();
             = f.getName();
            
        }
    }
New to GrepCode? Check out our FAQ X