[jackson-annotations] 29/207: Work on [JACKSON-714], add @JsonFormat annotation

Timo Aaltonen tjaalton at moszumanska.debian.org
Sat Sep 6 13:55:36 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 f7b0a16754be7a35a8ee34507bf164c6035f4b35
Author: Tatu Saloranta <tsaloranta at gmail.com>
Date:   Tue Feb 21 17:53:21 2012 -0800

    Work on [JACKSON-714], add @JsonFormat annotation
---
 .../fasterxml/jackson/annotation/JsonFormat.java   | 104 +++++++++++++++++++++
 1 file changed, 104 insertions(+)

diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java b/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java
new file mode 100644
index 0000000..8f78fa0
--- /dev/null
+++ b/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java
@@ -0,0 +1,104 @@
+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;
+
+/**
+ * General-purpose annotation used for configuring details of how
+ * values of properties are to be serialized.
+ * Unlike most other Jackson annotations, annotation does not
+ * have specific universal interpretation: instead, effect depends on datatype
+ * of property being annotated (or more specifically, deserializer
+ * and serializer being used).
+ *<p>
+ * Common uses include choosing between alternate representations -- for example,
+ * whether {@link java.util.Date} is to be serialized as number (Java timestamp)
+ * or String (such as ISO-8601 compatible time value) -- as well as configuring
+ * exact details with {@link #pattern} property.
+ * 
+ * @since 2.0
+ */
+ at Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
+ at Retention(RetentionPolicy.RUNTIME)
+ at JacksonAnnotation
+public @interface JsonFormat
+{
+
+    /**
+     * Datatype-specific additional piece of configuration that may be used
+     * to further refine formatting aspects. This may, for example, determine
+     * low-level format String used for {@link java.util.Date} serialization;
+     * however, exact use is determined by specific <code>JsonSerializer</code>
+     */
+    public String pattern() default "";
+
+    public Shape shape() default Shape.ANY;
+    
+    /*
+    /**********************************************************
+    /* Value enumeration(s) needed
+    /**********************************************************
+     */
+
+    /**
+     * Value enumeration used for indicating preferred Shape; translates
+     * loosely to JSON types, with some extra values to indicate less precise
+     * choices (i.e. allowing one of multiple actual shapes)
+     */
+    public enum Shape
+    {
+        /**
+         * Marker enum value that indicates "default" (or "whatever") choice; needed
+         * since Annotations can not have null values for enums.
+         */
+        ANY,
+
+        /**
+         * Value that indicates shape should not be structural (that is, not
+         * {@link #ARRAY} or {@link #OBJECT}, but can be any other shape.
+         */
+        SCALAR,
+
+        /**
+         * Value that indicates that (JSON) Array type should be used.
+         */
+        ARRAY,
+        
+        /**
+         * Value that indicates that (JSON) Object type should be used.
+         */
+        OBJECT,
+
+        /**
+         * Value that indicates that a numeric (JSON) type should be used
+         * (but does not specify whether integer or floating-point representation
+         * should be used)
+         */
+        NUMBER,
+
+        /**
+         * Value that indicates that floating-point numeric type should be used
+         */
+        NUMBER_FLOAT,
+
+        /**
+         * Value that indicates that integer number type should be used
+         * (and not {@link #NUMBER_FLOAT}).
+         */
+        NUMBER_INT,
+
+        /**
+         * Value that indicates that (JSON) String type should be used.
+         */
+        STRING,
+        
+        /**
+         * Value that indicates that (JSON) boolean type
+         * (true, false) should be used.
+         */
+        BOOLEAN
+        ;
+    }
+}

-- 
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