[ https://issues.apache.org/jira/browse/GROOVY-10208?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
A. Lepe updated GROOVY-10208: ----------------------------- Description: Json classes in `groovy.json` do not support `LocalDate`, `LocalTime`, `LocalDateTime`, etc classes. Google gson supports those classes without issues. 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]] // In Google GSON, the date is exported and imported correctly as LocalDateTime.{code} was: Json classes in `groovy.json` do not support `LocalDate`, `LocalTime`, `LocalDateTime`, etc classes. Google gson supports those classes without issues. 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 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]] // In Google GSON, the date is exported and imported correctly as LocalDateTime.{code} > 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. Google gson supports those classes without > issues. > 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]] > // In Google GSON, the date is exported and imported correctly as > LocalDateTime.{code} -- This message was sent by Atlassian Jira (v8.3.4#803005)