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

Allow converting JsonParserLax into a roughly normal Groovy map

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.4.3, 2.4.4
    • None
    • JSON
    • None
    • 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

              Unassigned Unassigned
              luyseyal Stephen Olander-Waters
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: