You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "A. Lepe (Jira)" <ji...@apache.org> on 2021/08/30 10:23:00 UTC

[jira] [Resolved] (GROOVY-10208) Add LocalDate/LocalTime/LocalDateTime support in JsonBuilder

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

A. Lepe resolved GROOVY-10208.
------------------------------
    Resolution: Fixed

> Add LocalDate/LocalTime/LocalDateTime support in JsonBuilder
> ------------------------------------------------------------
>
>                 Key: GROOVY-10208
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10208
>             Project: Groovy
>          Issue Type: Improvement
>    Affects Versions: 3.0.8
>            Reporter: A. Lepe
>            Priority: Trivial
>              Labels: json, jsonBuilder
>
> Json classes in `groovy.json` do not support `LocalDate`, `LocalTime`, `LocalDateTime`, etc classes.
> Classes like `Date`, `Calendar` and `SimpleDateFormat` are used, which (as you know) are no longer recommended. It would be nice to replace those classes with the recommended ones.
> Affected classes:
>  * DefaultJsonGenerator
>  * JsonGenerator
>  * JsonOutput
>  
> Example:
> {code:java}
> // Setting date and time in JSON:
> def map = [
>     date : LocalDateTime.now()
> ]
> def json = new JsonBuilder(map).toPrettyString()
> println json
> // prints:
> {
>     "date": {
>         "dayOfYear": 242,
>         "month": "AUGUST",
>         "second": 56,
>         "hour": 15,
>         "nano": 337326000,
>         "year": 2021,
>         "dayOfMonth": 30,
>         "minute": 51,
>         "monthValue": 8,
>         "dayOfWeek": "MONDAY",
>         "chronology": {
>             "calendarType": "iso8601",
>             "id": "ISO"
>         }
>     }
> }
> // Parsing that object with JsonSlurper:
> def importMap = new JsonSlurper().parseText(json)
> println importMap.date
> // prints:
> [dayOfYear:242, month:AUGUST, second:56, hour:15, nano:337326000, year:2021, dayOfMonth:30, minute:51, monthValue:8, dayOfWeek:MONDAY, chronology:[calendarType:iso8601, id:ISO]]
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)