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

JsonBuilder list handling improvement

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.3.0-beta-1
    • Component/s: JSON
    • Labels:
      None

      Description

      Currently to create json from a list of objects we have to do something like this:

      def songs = [new Song (title: "Title 1"), new Song (title: "Title 2"), ...]
      
      JsonBuilder json = new JsonBuilder ()
      def map = json {
          songs songs.collect { Song s ->
              json {
                  title s.title
              }
          }
      } 
      

      I would like to write:

      JsonBuilder json = new JsonBuilder ()
      def map = json {
          songs songs, { Song s ->
              title s.title
          }
      } 
      

      It is less code and easier to use and read.

      Implementation with tests and doc update is here:

      https://github.com/hauner/groovy-core/commits/jsonbuilder

        Attachments

          Activity

            People

            • Assignee:
              Guillaume Guillaume Delcroix
              Reporter:
              hauner Martin Hauner
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: