[jackson-annotations] 170/207: Add @JsonFormat.Value#timeZoneAsString()

Timo Aaltonen tjaalton at moszumanska.debian.org
Sat Sep 6 13:55:51 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 b61db147bb9ef98782f25d7c8d9802615ebdddb1
Author: Tatu Saloranta <tatu.saloranta at iki.fi>
Date:   Thu Mar 27 20:36:01 2014 -0700

    Add @JsonFormat.Value#timeZoneAsString()
---
 release-notes/VERSION                              |  1 +
 .../fasterxml/jackson/annotation/JsonFormat.java   | 63 +++++++++++++++++-----
 2 files changed, 52 insertions(+), 12 deletions(-)

diff --git a/release-notes/VERSION b/release-notes/VERSION
index c805620..3e64d17 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -5,6 +5,7 @@ NOTE: Annotations module will never contain changes in patch versions,
  only .0 releases can have changes.
 
 #31: Allow use of `@JsonPropertyOrder` for properties (not just classes)
+- Add `JsonFormat.Value#timeZoneAsString` (needed by Joda module)
 
 ------------------------------------------------------------------------
 === History: ===
diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java b/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java
index 0efce6c..a0e9e92 100644
--- a/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java
+++ b/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java
@@ -185,7 +185,11 @@ public @interface JsonFormat
         private final String pattern;
         private final Shape shape;
         private final Locale locale;
-        private final TimeZone timezone;
+
+        private final String timezoneStr;
+
+        // lazily constructed when created from annotations
+        private TimeZone _timezone;
 
         public Value() {
             this("", Shape.ANY, "", "");
@@ -197,11 +201,12 @@ public @interface JsonFormat
 
         public Value(String p, Shape sh, String localeStr, String tzStr)
         {
-            this(p, sh
-                    ,(localeStr == null || localeStr.length() == 0 || DEFAULT_LOCALE.equals(localeStr)) ?
-                            null : new Locale(localeStr)
-                    ,(tzStr == null || tzStr.length() == 0 || DEFAULT_TIMEZONE.equals(tzStr)) ?
-                            null : TimeZone.getTimeZone(tzStr)
+            this(p, sh,
+                    (localeStr == null || localeStr.length() == 0 || DEFAULT_LOCALE.equals(localeStr)) ?
+                            null : new Locale(localeStr),
+                    (tzStr == null || tzStr.length() == 0 || DEFAULT_TIMEZONE.equals(tzStr)) ?
+                            null : tzStr,
+                    null
             );
         }
 
@@ -213,40 +218,74 @@ public @interface JsonFormat
             pattern = p;
             shape = sh;
             locale = l;
-            timezone = tz;
+            _timezone = tz;
+            timezoneStr = null;
+        }
+
+        /**
+         * @since 2.4
+         */
+        public Value(String p, Shape sh, Locale l, String tzStr, TimeZone tz)
+        {
+            pattern = p;
+            shape = sh;
+            locale = l;
+            _timezone = tz;
+            timezoneStr = tzStr;
         }
 
         /**
          * @since 2.1
          */
         public Value withPattern(String p) {
-            return new Value(p, shape, locale, timezone);
+            return new Value(p, shape, locale, timezoneStr, _timezone);
         }
 
         /**
          * @since 2.1
          */
         public Value withShape(Shape s) {
-            return new Value(pattern, s, locale, timezone);
+            return new Value(pattern, s, locale, timezoneStr, _timezone);
         }
 
         /**
          * @since 2.1
          */
         public Value withLocale(Locale l) {
-            return new Value(pattern, shape, l, timezone);
+            return new Value(pattern, shape, l, timezoneStr, _timezone);
         }
 
         /**
          * @since 2.1
          */
         public Value withTimeZone(TimeZone tz) {
-            return new Value(pattern, shape, locale, tz);
+            return new Value(pattern, shape, locale, null, tz);
         }
         
         public String getPattern() { return pattern; }
         public Shape getShape() { return shape; }
         public Locale getLocale() { return locale; }
-        public TimeZone getTimeZone() { return timezone; }
+
+        /**
+         * Alternate access (compared to {@link #getTimeZone()}) which is useful
+         * when caller just wants time zone id to convert, but not as JDK
+         * provided {@link TimeZone}
+         * 
+         * @since 2.4
+         */
+        public String timeZoneAsString() {
+            if (_timezone != null) {
+                return _timezone.getID();
+            }
+            return timezoneStr;
+        }
+        
+        public TimeZone getTimeZone() {
+            TimeZone tz = _timezone;
+            if (tz == null) {
+                _timezone = tz = TimeZone.getTimeZone(timezoneStr);
+            }
+            return tz;
+        }
     }
 }

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