You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Stephen Olander-Waters (JIRA)" <ji...@apache.org> on 2015/07/30 21:08:06 UTC

[jira] [Commented] (GROOVY-7532) Allow converting JsonParserLax into a roughly normal Groovy map

    [ https://issues.apache.org/jira/browse/GROOVY-7532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14648136#comment-14648136 ] 

Stephen Olander-Waters commented on GROOVY-7532:
------------------------------------------------

This works but a convenience method would be nice:
{code}
def slurpOpts = jsonSlurperLAX.parse(new File("test.conf"))
slurpOpts.each {k, v -> configOpts2.put(k, slurpOpts.get(k))}
{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)