From 85f5f0c87db7958bfcdfbea1c9326ec1d0aa919f Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Sun, 31 May 2015 11:44:07 -0700 Subject: [PATCH] fix #60, Add `Nullean` value type. --- release-notes/VERSION | 2 + .../fasterxml/jackson/annotation/Nullean.java | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/main/java/com/fasterxml/jackson/annotation/Nullean.java diff --git a/release-notes/VERSION b/release-notes/VERSION index 2cf35b30..c32ba342 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -15,6 +15,8 @@ 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 + and usage of default values, not just explicit true/false. - Add `JsonInclude.Include.NON_ABSENT` value, for excluding "absent" Optional values. 2.5.0 (01-Jan-2015) diff --git a/src/main/java/com/fasterxml/jackson/annotation/Nullean.java b/src/main/java/com/fasterxml/jackson/annotation/Nullean.java new file mode 100644 index 00000000..051b474f --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/annotation/Nullean.java @@ -0,0 +1,38 @@ +package com.fasterxml.jackson.annotation; + +/** + * Nullable 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 + * {@link java.lang.Boolean} not allowed as solution). + *

+ * Note: although use of `true` and `false` would be more convenient, they + * can not be chosen since they are Java keyword and compiler won't allow + * the choice. And since enum naming convention suggests all-upper-case, + * that is what is done here. + * + * @since 2.6 + */ +public enum Nullean +{ + /** + * Value that indicates that the annotation property is explicitly defined to + * be enabled, or true. + */ + TRUE, + + /** + * Value that indicates that the annotation property is explicitly defined to + * be disabled, or false. + */ + FALSE, + + /** + * Value that indicates that the annotation property does NOT have an explicit + * definition of enabled/disabled (or true/false); instead, a higher-level + * configuration value is used; or lacking higher-level global setting, + * default. + */ + DEFAULT; +}