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

Allow converting JsonParserLax into a roughly normal Groovy map

    XMLWordPrintableJSON

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.4.3, 2.4.4
    • Fix Version/s: None
    • Component/s: JSON
    • Labels:
      None
    • Environment:
      Linux
      OpenJDK 7

      Description

      Please allow converting JsonParserLax into a roughly normal Groovy map so the following code works.

      This is important because JsonParserLax is the only one that allows comments in the JSON file.

      import groovy.json.JsonSlurper
      import groovy.json.JsonParserType
      
      def jsonSlurper = new JsonSlurper()
      def configOpts = jsonSlurper.parse(new File("test.conf"))
      assert configOpts.clientId instanceof String
      configOpts.newField = configOpts.newField ?: 25
      
      def jsonSlurperLAX = new JsonSlurper().setType(JsonParserType.LAX)
      def configOpts2 = jsonSlurperLAX.parse(new File("test.conf"))
      assert configOpts2.clientId instanceof String
      //next line throws "Not that kind of map" exception
      // It needs to be converted to a more normal Groovy structure.
      configOpts2.newField = configOpts2.newField ?: 25
      

      Example config file:

      {
        "clientId": "abc1234"
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                luyseyal Stephen Olander-Waters
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: