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

Dates.isJsonDate only recognizes Javascript Date's toJSON() Format

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.3, 2.3.7
    • Fix Version/s: 2.4.4
    • Component/s: JSON
    • Labels:

      Description

      groovy.json.internal.Dates#isJsonDate is always returns false for valid JSON date. This causes INDEX_OVERLAY parser to not parse dates even if checkDates was set to true

      See the implementation code:

      public static boolean isJsonDate(char[] charArray, int start, int to) {
              boolean valid = true;
              final int length = to - start;
      
              if (length != JSON_TIME_LENGTH) {
                  return false;
              }
      
              valid &= (charArray[start + 19] == '.');
      
              if (!valid) {
                  return false;
              }
      

      However valid JSON date looks like:

      2014-10-21T15:15:56+0000
      

      so there is no dots in this string so this method will always return false. This consequently leads to groovy.json.internal.CharSequenceValue#doToValue returns string instead of date so parser will never actually parse dates properly

      Test example:

      import  groovy.json.*
      def o = new JsonSlurper().
          setType(JsonParserType.INDEX_OVERLAY).
              setCheckDates(true).
                  parseText(JsonOutput.toJson([a : new Date()]))
      
      assertEquals(Date.class, o.a)
      

        Attachments

          Activity

            People

            • Assignee:
              pascalschumacher Pascal Schumacher
              Reporter:
              cy6ergn0m Sergey Mashkov
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: