diff --git a/release-notes/VERSION b/release-notes/VERSION index c32ba342..dd6938da 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -15,7 +15,7 @@ NOTE: Annotations module will never contain changes in patch versions, #56: Improve `ObjectIdGenerators.key()` to handle `null` appropriately by returning `null` #58: Add new properties for `@JsonIgnoreProperties`, "allowGetters", "allowSetters" -#60: Add new value type, `Nullean`, for "nullable booleans", to support proper handling +#60: Add new value type, `OptBoolean`, for "optional booleans", to support proper handling and usage of default values, not just explicit true/false. - Add `JsonInclude.Include.NON_ABSENT` value, for excluding "absent" Optional values. diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonIgnoreProperties.java b/src/main/java/com/fasterxml/jackson/annotation/JsonIgnoreProperties.java index 79fe8ca8..dfccc317 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonIgnoreProperties.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonIgnoreProperties.java @@ -55,6 +55,9 @@ * This is commonly set to support defining "read-only" properties; ones * for which there is a getter, but no matching setter: in this case, * properties should be ignored for deserialization but NOT serialization. + * Another way to think about this setting is that setting it to `true` + * will "disable" ignoring of getters. + *

* Default value is `false`, which means that getters with matching names * will be ignored. * @@ -68,6 +71,9 @@ * This could be used to specify "write-only" properties; ones * that should not be serialized out, but that may be provided in for * deserialization. + * Another way to think about this setting is that setting it to `true` + * will "disable" ignoring of setters. + *

* Default value is `false`, which means that setters with matching names * will be ignored. * diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonProperty.java b/src/main/java/com/fasterxml/jackson/annotation/JsonProperty.java index 4ba32cb3..db224570 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonProperty.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonProperty.java @@ -90,8 +90,71 @@ * It may also be used by Jackson extension modules; core jackson databind * does not have any automated handling beyond simply exposing this * value through bean property introspection. + *

+ * It is possible that in future this annotation could be used for value + * defaulting, and especially for default values of Creator properties, + * since they support {@link #required()} in 2.6 and above. * * @since 2.5 */ String defaultValue() default ""; + + /** + * Optional property that may be used to change the way visibility of + * accessors (getter, field-as-getter) and mutators (contructor parameter, + * setter, field-as-setter) is determined, either so that otherwise + * non-visible accessors (like private getters) may be used; or that + * otherwise visible accessors are ignored. + *

+ * Default value os {@link Access#AUTO} which means that access is determined + * solely based on visibility and other annotations. + * + * @since 2.6 + */ + Access access() default Access.AUTO; + + /** + * Various options for {@link #access} property, specifying how property + * may be accessed during serialization ("read") and deserialization ("write") + * (note that the direction of read and write is from perspective of the property, + * not from external data format: this may be confusing in some contexts). + *

+ * Note that while this annotation modifies access to annotated property, + * its effects may be further overridden by {@link JsonIgnore} property: + * if both annotations are present on an accessors, {@link JsonIgnore} + * has precedence over this property. + * + * @since 2.6 + */ + public enum Access + { + /** + * Access setting which means that visibility rules are to be used + * to automatically determine read- and/or write-access of this property. + */ + AUTO, + + /** + * Access setting that means that the property may only be read for serialization, + * but not written (set) during deserialization. + */ + READ_ONLY, + + /** + * Access setting that means that the property may only be written (set) + * for deserialization, + * but will not be read (get) on serialization, that is, the value of the property + * is not included in serialization. + */ + WRITE_ONLY, + + /** + * Access setting that means that the property will be accessed for both + * serialization (writing out values as external representation) + * and deserialization (reading values from external representation), + * regardless of visibility rules. + */ + READ_WRITE + ; + } } diff --git a/src/main/java/com/fasterxml/jackson/annotation/Nullean.java b/src/main/java/com/fasterxml/jackson/annotation/OptBoolean.java similarity index 92% rename from src/main/java/com/fasterxml/jackson/annotation/Nullean.java rename to src/main/java/com/fasterxml/jackson/annotation/OptBoolean.java index 051b474f..8e88e4a8 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/Nullean.java +++ b/src/main/java/com/fasterxml/jackson/annotation/OptBoolean.java @@ -1,7 +1,7 @@ package com.fasterxml.jackson.annotation; /** - * Nullable Boolean value, "nullean". Needed just because Java annotations + * Optional Boolean value ("nullean"). Needed just because Java annotations * can not take 'null' as a value (even as default), so there is no * way to distinguish between explicit `true` and `false`, and lack of * choice (related: annotations are limited to primitives, so @@ -14,7 +14,7 @@ * * @since 2.6 */ -public enum Nullean +public enum OptBoolean { /** * Value that indicates that the annotation property is explicitly defined to