[ 
https://issues.apache.org/jira/browse/GROOVY-7532?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Stephen Olander-Waters updated GROOVY-7532:
-------------------------------------------
    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.

{code}
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
{code}

Example config file:
{code}
{
  "clientId": "abc1234"
}
{code}

  was:
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.

{code}
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
// whereas supporting useValues would work
configOpts2.newField = configOpts2.newField ?: 25
{code}

Example config file:
{code}
{
  "clientId": "abc1234"
}
{code}


> Allow converting JsonParserLax into a roughly normal Groovy map 
> ----------------------------------------------------------------
>
>                 Key: GROOVY-7532
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7532
>             Project: Groovy
>          Issue Type: New Feature
>          Components: JSON
>    Affects Versions: 2.4.3, 2.4.4
>         Environment: Linux
> OpenJDK 7
>            Reporter: Stephen Olander-Waters
>            Assignee: Guillaume Laforge
>            Priority: Minor
>
> 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.
> {code}
> 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
> {code}
> Example config file:
> {code}
> {
>   "clientId": "abc1234"
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to