1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
| public enum MapperFeature implements ConfigFeature { /* /****************************************************** /* 通用配置 /****************************************************** */
/** * 是否开启注解 */ USE_ANNOTATIONS(true),
/** * 使用getter方法来作为setter方法(一般只处理集合和Maps,和其他没有setter的类型)。 该属性决定是否不需要setter方法,而只需要getter方法来修改属性。 */ USE_GETTERS_AS_SETTERS(true),
/** * Feature that determines how <code>transient</code> modifier for fields * is handled: if disabled, it is only taken to mean exclusion of the field * as accessor; if true, it is taken to imply removal of the whole property. * <p> * Feature is disabled by default, meaning that existence of `transient` * for a field does not necessarily lead to ignoral of getters or setters * but just ignoring the use of field for access. * * @since 2.6 */ PROPAGATE_TRANSIENT_MARKER(false),
/* /****************************************************** /* Introspection-based property auto-detection /****************************************************** */
/** * 该特性决定是否使用creator方法来根据公共构造函数以及名字为“valueOf”的静态单参数方法自动检测。 */ AUTO_DETECT_CREATORS(true),
/** * 这个特性决定是否非静态字段被当做属性。如果true,则所有公共成员字段都被当做属性, 否则只有注解,才会被当做属性字段。 */ AUTO_DETECT_FIELDS(true),
/** * 该特性决定是否使用“getter”方法来根据标准bean命名转换方式来自动检测。如果true,则所有公共的带有一个参数 * 并且前缀为get的方法都将被当做getter方法。如果false,只会把显式注解的作为getter方法。 */ AUTO_DETECT_GETTERS(true),
/** * 获取getter方法,前缀为is */ AUTO_DETECT_IS_GETTERS(true),
/** * 该特性决定是否使用“setter”方法来根据标准bean命名转换方式来自动检测。如果true,则所有公共的带有一个参数 * 并且前缀为set的方法都将被当做setter方法。如果false,只会把显式注解的作为setter方法。 */ AUTO_DETECT_SETTERS(true),
/** * 如果这个配置为false时,只有存在对应的构造器、setter或者field时,才调用getter */ REQUIRE_SETTERS_FOR_GETTERS(false),
/** * Feature that determines whether member fields declared as 'final' may * be auto-detected to be used mutators (used to change value of the logical * property) or not. If enabled, 'final' access modifier has no effect, and * such fields may be detected according to usual visibility and inference * rules; if disabled, such fields are NOT used as mutators except if * explicitly annotated for such use. * <p> * Feature is enabled by default, for backwards compatibility reasons. * * @since 2.2 */ ALLOW_FINAL_FIELDS_AS_MUTATORS(true),
/** * Feature that determines whether member mutators (fields and * setters) may be "pulled in" even if they are not visible, * as long as there is a visible accessor (getter or field) with same name. * For example: field "value" may be inferred as mutator, * if there is visible or explicitly marked getter "getValue()". * If enabled, inferring is enabled; otherwise (disabled) only visible and * explicitly annotated accessors are ever used. * <p> * Note that 'getters' are never inferred and need to be either visible (including * bean-style naming) or explicitly annotated. * <p> * Feature is enabled by default. * * @since 2.2 */ INFER_PROPERTY_MUTATORS(true),
/** * Feature that determines handling of <code>java.beans.ConstructorProperties<code> * annotation: when enabled, it is considered as alias of * {@link com.fasterxml.jackson.annotation.JsonCreator}, to mean that constructor * should be considered a property-based Creator; when disabled, only constructor * parameter name information is used, but constructor is NOT considered an explicit * Creator (although may be discovered as one using other annotations or heuristics). * <p> * Feature is mostly used to help interoperability with frameworks like Lombok * that may automatically generate <code>ConstructorProperties</code> annotation * but without necessarily meaning that constructor should be used as Creator * for deserialization. * <p> * Feature is enabled by default. * * @since 2.9 */ INFER_CREATOR_FROM_CONSTRUCTOR_PROPERTIES(true),
/* /****************************************************** /* Access modifier handling /****************************************************** */
/** * Feature that determines whether method and field access * modifier settings can be overridden when accessing * properties. If enabled, method * {@link java.lang.reflect.AccessibleObject#setAccessible} * may be called to enable access to otherwise unaccessible objects. * <p> * Note that this setting may have significant performance implications, * since access override helps remove costly access checks on each * and every Reflection access. If you are considering disabling * this feature, be sure to verify performance consequences if usage * is performance sensitive. * Also note that performance effects vary between Java platforms * (JavaSE vs Android, for example), as well as JDK versions: older * versions seemed to have more significant performance difference. * <p> * Conversely, on some platforms, it may be necessary to disable this feature * as platform does not allow such calls. For example, when developing * Applets (or other Java code that runs on tightly restricted sandbox), * it may be necessary to disable the feature regardless of performance effects. * <p> * Feature is enabled by default. */ CAN_OVERRIDE_ACCESS_MODIFIERS(true),
/** * Feature that determines that forces call to * {@link java.lang.reflect.AccessibleObject#setAccessible} even for * <code>public</code> accessors -- that is, even if no such call is * needed from functionality perspective -- if call is allowed * (that is, {@link #CAN_OVERRIDE_ACCESS_MODIFIERS} is set to true). * The main reason to enable this feature is possible performance * improvement as JDK does not have to perform access checks; these * checks are otherwise made for all accessors, including public ones, * and may result in slower Reflection calls. Exact impact (if any) * depends on Java platform (Java SE, Android) as well as JDK version. * <p> * Feature is enabled by default, for legacy reasons (it was the behavior * until 2.6) * * @since 2.7 */ OVERRIDE_PUBLIC_ACCESS_MODIFIERS(true),
/* /****************************************************** /* Type-handling features /****************************************************** */
/** * 是否使用运行时动态类型,还是声明的静态类型 */ USE_STATIC_TYPING(false),
/* /****************************************************** /* View-related features /****************************************************** */
/** * 该特性决定拥有view注解的属性是否在JSON序列化视图中。如果true,则非注解视图,也包含; * 否则,它们将会被排除在外。 */ DEFAULT_VIEW_INCLUSION(true),
/* /****************************************************** /* Generic output features /****************************************************** */
/** * 是否对属性使用排序,默认排序按照字母顺序 */ SORT_PROPERTIES_ALPHABETICALLY(false),
/* /****************************************************** /* Name-related features /****************************************************** */
/** * 反序列化是否忽略大小写 */ ACCEPT_CASE_INSENSITIVE_PROPERTIES(false),
/** * Feature that determines if Enum deserialization should be case sensitive or not. * If enabled, Enum deserialization will ignore case, that is, case of incoming String * value and enum id (dependant on other settings, either `name()`, `toString()`, or * explicit override) do not need to match. * <p> * Feature is disabled by default. * * @since 2.9 */ ACCEPT_CASE_INSENSITIVE_ENUMS(false),
/** * Feature that can be enabled to make property names be * overridden by wrapper name (usually detected with annotations * as defined by {@link AnnotationIntrospector#findWrapperName}. * If enabled, all properties that have associated non-empty Wrapper * name will use that wrapper name instead of property name. * If disabled, wrapper name is only used for wrapping (if anything). * <p> * Feature is disabled by default. * * @since 2.1 */ USE_WRAPPER_NAME_AS_PROPERTY_NAME(false),
/** * Feature that may be enabled to enforce strict compatibility with * Bean name introspection, instead of slightly different mechanism * Jackson defaults to. * Specific difference is that Jackson always lower cases leading upper-case * letters, so "getURL()" becomes "url" property; whereas standard Bean * naming <b>only</b> lower-cases the first letter if it is NOT followed by * another upper-case letter (so "getURL()" would result in "URL" property). * <p> * Feature is disabled by default for backwards compatibility purposes: earlier * Jackson versions used Jackson's own mechanism. * * @since 2.5 */ USE_STD_BEAN_NAMING(false),
/** * Feature that when enabled will allow explicitly named properties (i.e., fields or methods * annotated with {@link com.fasterxml.jackson.annotation.JsonProperty}("explicitName")) to * be re-named by a {@link PropertyNamingStrategy}, if one is configured. * <p> * Feature is disabled by default. * * @since 2.7 */ ALLOW_EXPLICIT_PROPERTY_RENAMING(false),
/* /****************************************************** /* Coercion features /****************************************************** */
/** * Feature that determines whether coercions from secondary representations are allowed * for simple non-textual scalar types: numbers and booleans. This includes `primitive` * types and their wrappers, but excludes `java.lang.String` and date/time types. * <p> * When feature is disabled, only strictly compatible input may be bound: numbers for * numbers, boolean values for booleans. When feature is enabled, conversions from * JSON String are allowed, as long as textual value matches (for example, String * "true" is allowed as equivalent of JSON boolean token `true`; or String "1.0" * for `double`). * <p> * Note that it is possible that other configurability options can override this * in closer scope (like on per-type or per-property basis); this is just the global * default. * <p> * Feature is enabled by default (for backwards compatibility since this was the * default behavior) * * @since 2.9 */ ALLOW_COERCION_OF_SCALARS(true),
/* /****************************************************** /* Other features /****************************************************** */
/** * Feature that determines whether multiple registrations of same module * should be ignored or not; if enabled, only the first registration call * results in module being called, and possible duplicate calls are silently * ignored; if disabled, no checking is done and all registration calls are * dispatched to module. * <p> * Definition of "same module" is based on using {@link Module#getTypeId()}; * modules with same non-null <code>type id</code> are considered same for * purposes of duplicate registration. This also avoids having to keep track * of actual module instances; only ids will be kept track of (and only if * this feature is enabled). * <p> * Feature is enabled by default. * * @since 2.5 */ IGNORE_DUPLICATE_MODULE_REGISTRATIONS(true),
/** * Setting that determines what happens if an attempt is made to explicitly * "merge" value of a property, where value does not support merging; either * merging is skipped and new value is created (<code>true</code>) or * an exception is thrown (false). * <p> * Feature is disabled by default since non-mergeable property types are ignored * even if defaults call for merging, and usually explicit per-type or per-property * settings for such types should result in an exception. * * @since 2.9 */ IGNORE_MERGE_FOR_UNMERGEABLE(true);
private final boolean _defaultState; private final int _mask;
private MapperFeature(boolean defaultState) { _defaultState = defaultState; _mask = (1 << ordinal()); }
@Override public boolean enabledByDefault() { return _defaultState; }
@Override public int getMask() { return _mask; }
@Override public boolean enabledIn(int flags) { return (flags & _mask) != 0; } } 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
|