[ 
https://issues.apache.org/jira/browse/GROOVY-7127?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Pascal Schumacher updated GROOVY-7127:
--------------------------------------
    Fix Version/s:     (was: 2.5.0-beta-1)

> Dates.isJsonDate only recognizes Javascript Date's toJSON() Format
> ------------------------------------------------------------------
>
>                 Key: GROOVY-7127
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7127
>             Project: Groovy
>          Issue Type: Bug
>          Components: JSON
>    Affects Versions: 2.3.3, 2.3.7
>            Reporter: Sergey Mashkov
>            Assignee: Pascal Schumacher
>              Labels: contrib
>             Fix For: 2.4.4
>
>
> 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:
> {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;
>         }
> {code}
> However valid JSON date looks like:
> {noformat}
> 2014-10-21T15:15:56+0000
> {noformat}
> 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:
> {code}
> import  groovy.json.*
> def o = new JsonSlurper().
>     setType(JsonParserType.INDEX_OVERLAY).
>         setCheckDates(true).
>             parseText(JsonOutput.toJson([a : new Date()]))
> assertEquals(Date.class, o.a)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to