Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-6854

JsonOutput should be configurable with ISO 8601 UTC time zone instead of GMT

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.2
    • 2.5.0-alpha-1
    • JSON

    Description

      I believe ISO 8601 prefers the use of UTC over GMT as described in http://en.wikipedia.org/wiki/ISO_8601#Dates:

      Time zones in ISO 8601 are represented as local time (with the location unspecified), as UTC, or as an offset from UTC.

      GMT while similar, isn't exactly UTC. For example in GMT will format a date as:

      2014-03-12T19:02:35+0000
      

      instead of the arguably nicer 'Z' for UTC

      2014-03-12T19:02:35Z
      

      Java 7 introduced the "X" flag to use instead of the "Z" flag (which is RFC 822, not ISO 8601) for SimpleDateFormat, which finally made the class ISO 8601 compatible.

      Currently our team uses this workaround for JsonOutput to get it to format ISO dates correctly:

              def p = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXX")
              p.setTimeZone(TimeZone.getTimeZone('UTC'))
              JsonOutput.dateFormatter.set(p)
      

      I believe this should be the default for JsonOutput, with some sort of workaround available for Groovy users who are on JDK6 or earlier.

      If using JDK8 the new date/time library classes should probably be used instead.

      The JsonOutput class should really be reconsidered to be a candidate for refactoring to a more extendable structure. The limitations of it being an all-static utility class are apparent with its current date handling and also because it doesn't clients to extend it to print their own custom classes as well. The current method of just dumping all properties is often too verbose.

      Attachments

        Activity

          People

            jwagenleitner John Wagenleitner
            gcoller george coller
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: