[jackson-annotations] 31/207: Further updates to @JsonFormat annotations: add 'locale' and 'timezone' properties

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 39a4a282d1e1ffa3c69e77ea97a0ed7bc283f01f
Author: Tatu Saloranta <tsaloranta at gmail.com>
Date:   Fri Feb 24 16:00:54 2012 -0800

    Further updates to @JsonFormat annotations: add 'locale' and 'timezone' properties
---
 release-notes/VERSION                              | 17 +++++
 .../fasterxml/jackson/annotation/JsonFormat.java   | 73 ++++++++++++++++++++--
 2 files changed, 84 insertions(+), 6 deletions(-)

diff --git a/release-notes/VERSION b/release-notes/VERSION
new file mode 100644
index 0000000..3fc1bae
--- /dev/null
+++ b/release-notes/VERSION
@@ -0,0 +1,17 @@
+Version: 2.0.0
+
+Release date:
+  xx-Feb-2012
+
+Description:
+  The son of Jackson! Behold...
+
+New features:
+
+* [JACKSON-714] Add general-purpose '@JsonFormat' annotation
+
+------------------------------------------------------------------------
+=== History: ===
+------------------------------------------------------------------------
+
+[entries for versions 1.x and earlier not retained; refer to earlier releases)
diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java b/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java
index e5da780..f020099 100644
--- a/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java
+++ b/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java
@@ -4,6 +4,8 @@ import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
+import java.util.Locale;
+import java.util.TimeZone;
 
 /**
  * General-purpose annotation used for configuring details of how
@@ -33,6 +35,20 @@ import java.lang.annotation.Target;
 public @interface JsonFormat
 {
     /**
+     * Value that indicates that default {@link java.util.Locale}
+     * (from deserialization or serialization context) should be used:
+     * annotation does not define value to use.
+     */
+    public final static String DEFAULT_LOCALE = "##default";
+
+    /**
+     * Value that indicates that default {@link java.util.TimeZone}
+     * (from deserialization or serialization context) should be used:
+     * annotation does not define value to use.
+     */
+    public final static String DEFAULT_TIMEZONE = "##default";
+    
+    /**
      * 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;
@@ -40,7 +56,33 @@ public @interface JsonFormat
      */
     public String pattern() default "";
 
+    /**
+     * Structure to use for serialization: definition of mapping depends on datatype,
+     * but usually has straight-forward counterpart in data format (JSON).
+     * Note that commonly only a subset of shapes is available; and if 'invalid' value
+     * is chosen, defaults are usually used.
+     */
     public Shape shape() default Shape.ANY;
+
+    /**
+     * {@link java.util.Locale} to use for serialization (if needed).
+     * Special value of {@link #DEFAULT_LOCALE}
+     * can be used to mean "just use the default", where default is specified
+     * by the serialization context, which in turn defaults to system
+     * defaults ({@link java.util.Locale#getDefault()}) unless explicitly
+     * set to another locale.
+     */
+    public String locale() default DEFAULT_LOCALE;
+    
+    /**
+     * {@link java.util.TimeZone} to use for serialization (if needed).
+     * Special value of {@link #DEFAULT_TIMEZONE}
+     * can be used to mean "just use the default", where default is specified
+     * by the serialization context, which in turn defaults to system
+     * defaults ({@link java.util.TimeZone#getDefault()}) unless explicitly
+     * set to another locale.
+     */
+    public String timezone() default DEFAULT_TIMEZONE;
     
     /*
     /**********************************************************
@@ -122,16 +164,35 @@ public @interface JsonFormat
      */
     public static class Value
     {
-        public final String pattern;
-        public final Shape shape;
-        
-        public Value(JsonFormat annotationInstance) {
-            this(annotationInstance.pattern(), annotationInstance.shape());
+        private final String pattern;
+        private final Shape shape;
+        private final Locale locale;
+        private final TimeZone timezone;
+
+        public Value(JsonFormat ann) {
+            this(ann.pattern(), ann.shape(), ann.locale(), ann.timezone());
+                    
         }
 
-        public Value(String p, Shape sh) {
+        public Value(String p, Shape sh, String localeStr, String tzStr)
+        {
             pattern = p;
             shape = sh;
+            if (localeStr == null || localeStr.length() == 0 || DEFAULT_LOCALE.equals(localeStr)) {
+                locale = null;
+            } else {
+                locale = new Locale(localeStr);
+            }
+            if (tzStr == null || tzStr.length() == 0 || DEFAULT_TIMEZONE.equals(tzStr)) {
+                timezone = null;
+            } else {
+                timezone = TimeZone.getTimeZone(tzStr);
+            }
         }
+        
+        public String getPattern() { return pattern; }
+        public Shape getShape() { return shape; }
+        public Locale getLocale() { return locale; }
+        public TimeZone getTimeZone() { return timezone; }
     }
 }

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