1 package com.fasterxml.jackson.databind; 2 3 import java.lang.reflect.Constructor; 4 import java.lang.reflect.Method; 5 import java.util.*; 6 7 import com.fasterxml.jackson.annotation.JsonFormat; 8 import com.fasterxml.jackson.annotation.JsonInclude; 9 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; 10 import com.fasterxml.jackson.databind.introspect.*; 11 import com.fasterxml.jackson.databind.type.TypeBindings; 12 import com.fasterxml.jackson.databind.util.Annotations; 13 import com.fasterxml.jackson.databind.util.Converter; 14 15 /** 16 * Basic container for information gathered by {@link ClassIntrospector} to 17 * help in constructing serializers and deserializers. 18 * Note that the main implementation type is 19 * {@link com.fasterxml.jackson.databind.introspect.BasicBeanDescription}, 20 * meaning that it is safe to upcast to this type. 21 */ 22 public abstract class BeanDescription 23 { 24 /** 25 * Bean type information, including raw class and possible 26 * generics information 27 */ 28 protected final JavaType _type; 29 30 /* 31 /********************************************************** 32 /* Life-cycle 33 /********************************************************** 34 */ 35 BeanDescription(JavaType type)36 protected BeanDescription(JavaType type) { 37 _type = type; 38 } 39 40 /* 41 /********************************************************** 42 /* Simple accesors 43 /********************************************************** 44 */ 45 46 /** 47 * Method for accessing declared type of bean being introspected, 48 * including full generic type information (from declaration) 49 */ getType()50 public JavaType getType() { return _type; } 51 getBeanClass()52 public Class<?> getBeanClass() { return _type.getRawClass(); } 53 54 /** 55 * @since 2.9 56 */ isNonStaticInnerClass()57 public boolean isNonStaticInnerClass() { 58 return getClassInfo().isNonStaticInnerClass(); 59 } 60 61 /** 62 * Method for accessing low-level information about Class this 63 * item describes. 64 */ getClassInfo()65 public abstract AnnotatedClass getClassInfo(); 66 67 /** 68 * Accessor for getting information about Object Id expected to 69 * be used for this POJO type, if any. 70 */ getObjectIdInfo()71 public abstract ObjectIdInfo getObjectIdInfo(); 72 73 /** 74 * Method for checking whether class being described has any 75 * annotations recognized by registered annotation introspector. 76 */ hasKnownClassAnnotations()77 public abstract boolean hasKnownClassAnnotations(); 78 79 /** 80 * Accessor for type bindings that may be needed to fully resolve 81 * types of member object, such as return and argument types of 82 * methods and constructors, and types of fields. 83 * 84 * @deprecated Since 2.7, should not need to access bindings directly 85 */ 86 @Deprecated bindingsForBeanType()87 public abstract TypeBindings bindingsForBeanType(); 88 89 /** 90 * Method for resolving given JDK type, using this bean as the 91 * generic type resolution context. 92 * 93 * @deprecated Since 2.8, should simply call <code>getType</code> of 94 * property accessor directly. 95 */ 96 @Deprecated resolveType(java.lang.reflect.Type jdkType)97 public abstract JavaType resolveType(java.lang.reflect.Type jdkType); 98 99 /** 100 * Method for accessing collection of annotations the bean 101 * class has. 102 */ getClassAnnotations()103 public abstract Annotations getClassAnnotations(); 104 105 /* 106 /********************************************************** 107 /* Basic API for finding properties 108 /********************************************************** 109 */ 110 111 /** 112 * @return Ordered Map with logical property name as key, and 113 * matching getter method as value. 114 */ findProperties()115 public abstract List<BeanPropertyDefinition> findProperties(); 116 getIgnoredPropertyNames()117 public abstract Set<String> getIgnoredPropertyNames(); 118 119 /** 120 * Method for locating all back-reference properties (setters, fields) bean has 121 * 122 * @since 2.9 123 */ findBackReferences()124 public abstract List<BeanPropertyDefinition> findBackReferences(); 125 126 /** 127 * Method for locating all back-reference properties (setters, fields) bean has 128 * 129 * @deprecated Since 2.9 use {@link #findBackReferences()} instead 130 */ 131 @Deprecated findBackReferenceProperties()132 public abstract Map<String,AnnotatedMember> findBackReferenceProperties(); 133 134 /* 135 /********************************************************** 136 /* Basic API for finding creator members 137 /********************************************************** 138 */ 139 getConstructors()140 public abstract List<AnnotatedConstructor> getConstructors(); 141 getFactoryMethods()142 public abstract List<AnnotatedMethod> getFactoryMethods(); 143 144 /** 145 * Method that will locate the no-arg constructor for this class, 146 * if it has one, and that constructor has not been marked as 147 * ignorable. 148 */ findDefaultConstructor()149 public abstract AnnotatedConstructor findDefaultConstructor(); 150 151 /** 152 * Method that can be called to locate a single-arg constructor that 153 * takes specified exact type (will not accept supertype constructors) 154 * 155 * @param argTypes Type(s) of the argument that we are looking for 156 */ findSingleArgConstructor(Class<?>.... argTypes)157 public abstract Constructor<?> findSingleArgConstructor(Class<?>... argTypes); 158 159 /** 160 * Method that can be called to find if introspected class declares 161 * a static "valueOf" factory method that returns an instance of 162 * introspected type, given one of acceptable types. 163 * 164 * @param expArgTypes Types that the matching single argument factory 165 * method can take: will also accept super types of these types 166 * (ie. arg just has to be assignable from expArgType) 167 */ findFactoryMethod(Class<?>.... expArgTypes)168 public abstract Method findFactoryMethod(Class<?>... expArgTypes); 169 170 /* 171 /********************************************************** 172 /* Basic API for finding property accessors 173 /********************************************************** 174 */ 175 176 /** 177 * Method for locating accessor (readable field, or "getter" method) 178 * that has 179 * {@link com.fasterxml.jackson.annotation.JsonValue} annotation, 180 * if any. If multiple ones are found, 181 * an error is reported by throwing {@link IllegalArgumentException} 182 * 183 * @since 2.9 184 */ findJsonValueAccessor()185 public abstract AnnotatedMember findJsonValueAccessor(); 186 findAnyGetter()187 public abstract AnnotatedMember findAnyGetter(); 188 189 /** 190 * Method used to locate a mutator (settable field, or 2-argument set method) 191 * of introspected class that 192 * implements {@link com.fasterxml.jackson.annotation.JsonAnySetter}. 193 * If no such mutator exists null is returned. If more than one are found, 194 * an exception is thrown. 195 * Additional checks are also made to see that method signature 196 * is acceptable: needs to take 2 arguments, first one String or 197 * Object; second any can be any type. 198 * 199 * @since 2.9 200 */ findAnySetterAccessor()201 public abstract AnnotatedMember findAnySetterAccessor(); 202 findMethod(String name, Class<?>[] paramTypes)203 public abstract AnnotatedMethod findMethod(String name, Class<?>[] paramTypes); 204 205 @Deprecated // since 2.9 findJsonValueMethod()206 public abstract AnnotatedMethod findJsonValueMethod(); 207 208 /** 209 * @deprecated Since 2.9: use {@link #findAnySetterAccessor} instead 210 */ 211 @Deprecated findAnySetter()212 public AnnotatedMethod findAnySetter() { 213 AnnotatedMember m = findAnySetterAccessor(); 214 if (m instanceof AnnotatedMethod) { 215 return (AnnotatedMethod) m; 216 } 217 return null; 218 } 219 220 /** 221 * @deprecated Since 2.9: use {@link #findAnySetterAccessor} instead 222 */ 223 @Deprecated findAnySetterField()224 public AnnotatedMember findAnySetterField() { 225 AnnotatedMember m = findAnySetterAccessor(); 226 if (m instanceof AnnotatedField) { 227 return m; 228 } 229 return null; 230 } 231 232 /* 233 /********************************************************** 234 /* Basic API, class configuration 235 /********************************************************** 236 */ 237 238 /** 239 * Method for finding annotation-indicated inclusion definition (if any); 240 * possibly overriding given default value. 241 *<p> 242 * NOTE: does NOT use global inclusion default settings as the base, unless 243 * passed as `defValue`. 244 * 245 * @since 2.7 246 */ findPropertyInclusion(JsonInclude.Value defValue)247 public abstract JsonInclude.Value findPropertyInclusion(JsonInclude.Value defValue); 248 249 /** 250 * Method for checking what is the expected format for POJO, as 251 * defined by defaults and possible annotations. 252 * Note that this may be further refined by per-property annotations. 253 * 254 * @since 2.1 255 */ findExpectedFormat(JsonFormat.Value defValue)256 public abstract JsonFormat.Value findExpectedFormat(JsonFormat.Value defValue); 257 258 /** 259 * Method for finding {@link Converter} used for serializing instances 260 * of this class. 261 * 262 * @since 2.2 263 */ findSerializationConverter()264 public abstract Converter<Object,Object> findSerializationConverter(); 265 266 /** 267 * Method for finding {@link Converter} used for serializing instances 268 * of this class. 269 * 270 * @since 2.2 271 */ findDeserializationConverter()272 public abstract Converter<Object,Object> findDeserializationConverter(); 273 274 /** 275 * Accessor for possible description for the bean type, used for constructing 276 * documentation. 277 * 278 * @since 2.7 279 */ findClassDescription()280 public String findClassDescription() { return null; } 281 282 /* 283 /********************************************************** 284 /* Basic API, other 285 /********************************************************** 286 */ 287 findInjectables()288 public abstract Map<Object, AnnotatedMember> findInjectables(); 289 290 /** 291 * Method for checking if the POJO type has annotations to 292 * indicate that a builder is to be used for instantiating 293 * instances and handling data binding, instead of standard 294 * bean deserializer. 295 */ findPOJOBuilder()296 public abstract Class<?> findPOJOBuilder(); 297 298 /** 299 * Method for finding configuration for POJO Builder class. 300 */ findPOJOBuilderConfig()301 public abstract JsonPOJOBuilder.Value findPOJOBuilderConfig(); 302 303 /** 304 * Method called to create a "default instance" of the bean, currently 305 * only needed for obtaining default field values which may be used for 306 * suppressing serialization of fields that have "not changed". 307 * 308 * @param fixAccess If true, method is allowed to fix access to the 309 * default constructor (to be able to call non-public constructor); 310 * if false, has to use constructor as is. 311 * 312 * @return Instance of class represented by this descriptor, if 313 * suitable default constructor was found; null otherwise. 314 */ instantiateBean(boolean fixAccess)315 public abstract Object instantiateBean(boolean fixAccess); 316 317 /** 318 * Method for finding out if the POJO specifies default view(s) to 319 * use for properties, considering both per-type annotations and 320 * global default settings. 321 * 322 * @since 2.9 323 */ findDefaultViews()324 public abstract Class<?>[] findDefaultViews(); 325 } 326