Add `JacksonAnnotationValue` helper/tag interface
diff --git a/release-notes/VERSION b/release-notes/VERSION
index 8c365c2..e607da9 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -21,6 +21,8 @@
and usage of default values, not just explicit true/false.
#61: dd new property, `@JsonProperty.access` (and matching enum) to support read-only/write-only properties
- Add `JsonInclude.Include.NON_ABSENT` value, for excluding "absent" Optional values.
+- Add tag interface `JacksonAnnotationValue` for helper types used for encapsuating information
+ for "complex" annotations (multi-property ones)
2.5.0 (01-Jan-2015)
diff --git a/src/main/java/com/fasterxml/jackson/annotation/JacksonAnnotationValue.java b/src/main/java/com/fasterxml/jackson/annotation/JacksonAnnotationValue.java
new file mode 100644
index 0000000..5d3ab97
--- /dev/null
+++ b/src/main/java/com/fasterxml/jackson/annotation/JacksonAnnotationValue.java
@@ -0,0 +1,22 @@
+package com.fasterxml.jackson.annotation;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * Marker interface used by value classes like {@link JsonFormat.Value} that are used
+ * to contain information from one of Jackson annotations, and can be directly
+ * instantiated from those annotations, as well as programmatically constructed
+ * and possibly merged. The reason for such marker is to allow generic handling of
+ * some of the annotations, as well as to allow easier injection of configuration
+ * from sources other than annotations.
+ *
+ * @since 2.6
+ */
+public interface JacksonAnnotationValue<A extends Annotation>
+{
+ /**
+ * Introspection method that may be used to find actual annotation that may be used
+ * as the source for value instance.
+ */
+ public Class<A> valueFor();
+}
diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java b/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java
index 6406f2e..9dab2b3 100644
--- a/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java
+++ b/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java
@@ -316,6 +316,7 @@
* annotation.
*/
public static class Value
+ implements JacksonAnnotationValue<JsonFormat> // since 2.6
{
private final String pattern;
private final Shape shape;
@@ -455,6 +456,11 @@
return (newFeats == features) ? this :
new Value(pattern, shape, locale, timezoneStr, _timezone, newFeats);
}
+
+ @Override
+ public Class<JsonFormat> valueFor() {
+ return JsonFormat.class;
+ }
public String getPattern() { return pattern; }
public Shape getShape() { return shape; }
diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java b/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java
index c5056d5..2986d54 100644
--- a/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java
+++ b/src/main/java/com/fasterxml/jackson/annotation/JsonInclude.java
@@ -28,7 +28,7 @@
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD,
ElementType.TYPE, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
-@com.fasterxml.jackson.annotation.JacksonAnnotation
+@JacksonAnnotation
public @interface JsonInclude
{
/**
@@ -132,4 +132,52 @@
;
}
+
+ /*
+ /**********************************************************
+ /* Value class used to enclose information
+ /**********************************************************
+ */
+
+ /**
+ * Helper class used to contain information from a single {@link JsonInclude}
+ * annotation.
+ *
+ * @since 2.6
+ */
+ public static class Value
+ implements JacksonAnnotationValue<JsonInclude> // since 2.6
+ {
+ protected final Include valueInclusion;
+ protected final Include contentInclusion;
+
+ public Value(JsonInclude src) {
+ valueInclusion = src.value();
+ contentInclusion = src.content();
+ }
+
+ /**
+ * Factory method to use for constructing an instance from instance of
+ * {@link JsonInclude}
+ */
+ public static Value from(JsonInclude src) {
+ if (src == null) {
+ return null;
+ }
+ return new Value(src);
+ }
+
+ @Override
+ public Class<JsonInclude> valueFor() {
+ return JsonInclude.class;
+ }
+
+ public Include getValueInclusion() {
+ return valueInclusion;
+ }
+
+ public Include getContentInclusion() {
+ return contentInclusion;
+ }
+ }
}