You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Pascal Schumacher (JIRA)" <ji...@apache.org> on 2015/06/26 17:21:05 UTC

[jira] [Assigned] (GROOVY-7127) Dates.isJsonDate only recognizes Javascript Date's toJSON() Format

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

Pascal Schumacher reassigned GROOVY-7127:
-----------------------------------------

    Assignee: Pascal Schumacher

> 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, 2.5.0-beta-1
>
>
> 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)