[jackson-annotations] 80/207: Implemented [Issue#4], add `@JsonIdentityReference` annotation

Timo Aaltonen tjaalton at moszumanska.debian.org
Sat Sep 6 13:55:41 UTC 2014


This is an automated email from the git hooks/post-receive script.

tjaalton pushed a commit to branch master
in repository jackson-annotations.

commit ccbc086ed1955f0eaaf4192819bece27adaa2f8c
Author: Tatu Saloranta <tsaloranta at salesforce.com>
Date:   Fri Aug 24 12:42:04 2012 -0700

    Implemented [Issue#4], add `@JsonIdentityReference` annotation
---
 release-notes/VERSION                              |  5 +++-
 .../jackson/annotation/JsonIdentityInfo.java       | 13 --------
 .../jackson/annotation/JsonIdentityReference.java  | 35 ++++++++++++++++++++++
 3 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/release-notes/VERSION b/release-notes/VERSION
index bcaf59c..1b73076 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -6,7 +6,10 @@ Release date:
 Description:
   New minor version.
 
-Fixes:
+New features:
+
+* [Issue#4]: Add '@JsonIdentityReference', to support use case where values of
+  a specific reference property are always serialized as ids, never as full POJO
 
 ------------------------------------------------------------------------
 === History: ===
diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonIdentityInfo.java b/src/main/java/com/fasterxml/jackson/annotation/JsonIdentityInfo.java
index f834fa2..9ccde66 100644
--- a/src/main/java/com/fasterxml/jackson/annotation/JsonIdentityInfo.java
+++ b/src/main/java/com/fasterxml/jackson/annotation/JsonIdentityInfo.java
@@ -72,17 +72,4 @@ public @interface JsonIdentityInfo
      * limited scope)
      */
     public Class<?> scope() default Object.class;
-
-    /**
-     * Marker to indicate whether the first reference to an identifiable
-     * POJO is to be serialized as POJO (false), or as id (true).
-     * All other references will be serialized using id.
-     *<p>
-     * Note that if value of 'true' is used, deserialization will require
-     * additional contextual information; and usually custom handler
-     * is required, and automatic handling may not be possible.
-     * 
-     * @since 2.1
-     */
-    public boolean firstAsId() default false;
 }
diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonIdentityReference.java b/src/main/java/com/fasterxml/jackson/annotation/JsonIdentityReference.java
new file mode 100644
index 0000000..27d97c0
--- /dev/null
+++ b/src/main/java/com/fasterxml/jackson/annotation/JsonIdentityReference.java
@@ -0,0 +1,35 @@
+package com.fasterxml.jackson.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Optional annotation that can be used for customizing details of a reference
+ * to Objects for which "Object Identity" is enabled (see {@link JsonIdentityInfo}).
+ * The main use case is that of enforcing use of Object Id even for the first
+ * time an Object is referenced, instead of first instance being serialized
+ * as full POJO.
+ * 
+ * @since 2.1
+ */
+ at Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE,
+    ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
+ at Retention(RetentionPolicy.RUNTIME)
+ at JacksonAnnotation
+public @interface JsonIdentityReference
+{
+    /**
+     * Marker to indicate whether all referenced values are to
+     * be serialized as ids (true); or by serializing the
+     * first encountered reference as POJO and only then as id (false).
+     *<p>
+     * Note that if value of 'true' is used, deserialization may require
+     * additional contextual information, and possibly using a custom
+     * id resolver -- the default handling may not be sufficient.
+     * 
+     * @since 2.1
+     */
+    public boolean alwaysAsId() default false;
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jackson-annotations.git



More information about the pkg-java-commits mailing list