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

Safe star dot operator

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Invalid
    • None
    • None
    • syntax
    • None

    Description

      Currently I would have to write code like this (in the Groovy Console) to be safe:

      def json = [
          messages: [
              [message: 'test']
          ],
          errors: null
      ]
      
      
      [
          *(json.messages ? json.messages*.message : []),
          *(json.errors ? json.errors*.message : [])
      ].join('\n')
      

      I would like to request for an operator like ?*. so I can write something like this:

      [
          *(json.messages?*.message ?: []),
          *(json.errors?*.message ?: [])
      ].join('\n')
      

      Not sure if it can be simplified further, but that's the idea.

      Attachments

        Activity

          People

            Unassigned Unassigned
            rkrisztian rkrisztian
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: