[groovy-user] JsonSlurp Lexing failed 1 error; after upgrading the Maven Groovy Eclipse Compiler

693 views
Skip to first unread message

Robert Brooks

unread,
Oct 9, 2014, 12:16:32 PM10/9/14
to us...@groovy.codehaus.org
Hi All,

After upgrading my 'maven's groovy-eclipse-compiler' to 2.8.0-01 and my 'groovy-all' artifact to 2.1.8. I am running into an error with the JsonSlurper. I believe it is a problem with upgrading because the same Json is parsed when use older versions (2.6.0-01, 2.1.6) maven's groovy-eclipse-compiler and groovy-all. I was forced to upgrade one module because a teammate decided to start writing Spock tests and the spring-core-0.7-groovy-2.0 module was not compatible with the mave

Lexing failed on line: 1, column: 2, while reading 'R', no possible valid JSON value or punctuation could be recognized.
groovy.json.JsonException
    at groovy.json.JsonLexer.nextToken(JsonLexer.java:82)
    at groovy.json.JsonSlurper.parseObject(JsonSlurper.java:172)
    at groovy.json.JsonSlurper.parse(JsonSlurper.java:75)
    at groovy.json.JsonSlurper.parseText(JsonSlurper.java:59)
    at resource.common.controller.auth.MasheryCredentialController.run(MasheryCredentialController.groovy:19)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:518)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:565)
    at resource.common.MasheryCredentialControllerTest.Credentials Request Handler should parse response and bind credential to
       Groovy context(MasheryCredentialControllerTest.groovy:38)


JSON Text:
{
    "ReadResponse": {
        "requestId": "scl-1svad-m:admin-services:o0n18r84",
        "version": "UNKNOWN",
        "startTime": "2013-02-06T20:00:20.691Z",
        "endTime": "2013-02-06T20:00:21.136Z",
        "processTime": 445,
        "uri": "http://localhost:8080/mgmt/admin-services/v1/credentials/A40C782D-40BD-4199-ACAB-F643DF17992F",
        "credential": {
            "id": "http://localhost:8080/mgmt/admin-services/v1/credentials/A40C782D-40BD-4199-ACAB-F643DF17992F",
            "username": "foobar",
            "password": "password",
            "active": true,
            "locked": false,
            "email": "Ijkjd...@fakeabchost.com",
            "businessUnit": {
                "id": "http://localhost:8080/mgmt/admin-services/v1/businessunits/2"
            },
            "applicationId": "D4804842-FB2E-4A30-B8F9-D1271B0A6B39"
        }
    }
}


pom.xml

      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <compilerId>groovy-eclipse-compiler</compilerId>
          <verbose>true</verbose>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-compiler</artifactId>
            <version>2.8.0-01</version>
          </dependency>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-batch</artifactId>
            <version>2.1.8-01</version>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <artifactId>groovy-eclipse-compiler</artifactId>
        <groupId>org.codehaus.groovy</groupId>
        <version>2.8.0-01</version>
        <extensions>true</extensions>
      </plugin>

    <dependency>
      <artifactId>groovy-all</artifactId>
      <groupId>org.codehaus.groovy</groupId>
      <version>2.1.8</version>
    </dependency>
  </dependencies> 

Guillaume Laforge

unread,
Oct 10, 2014, 3:51:21 AM10/10/14
to Groovy User
Could you try with a more recent version of both the Groovy Eclipse compiler and the Groovy all JAR?
--
Guillaume Laforge
Groovy Project Manager
Pivotal, Inc.

Robert Brooks

unread,
Oct 10, 2014, 12:21:31 PM10/10/14
to us...@groovy.codehaus.org
Thank you for the quick response. I did try this with groovy-all 2.3.7 and the groovy-eclipse-compiler 2.9.0-01 (which I believe is the latest.) However, I found the issue and it was because the code was using the JsonSlurper to parse the JSON file to a String first; and then a script would try to use the JsonSlurper to parse the String (of valid JSON) to a Map type. I am not really she why this does not work because the String is valid JSON, but see example below.

<Unit Test Setup>
InputStream stream = this.getClass().getClassLoader().getResourceAsStream(<path to a json file>)
InputStreamReader reader = new InputStreamReader(stream)
JsonSlurper slurper = new JsonSlurper()
String content =  slurper.parse(reader)


<Script code>
String content = binding.variables.content
JsonSlurper slurper = new JsonSlurper()
def content =  slurper.parse(reader)
assert content


The fix feels more like a work around, but it works.
<Unit Test Setup>
InputStream stream = this.getClass().getClassLoader().getResourceAsStream(<path to a json file>)
InputStreamReader reader = new InputStreamReader(stream)
JsonSlurper slurper = new JsonSlurper()
def content =  slurper.parse(reader)
JsonBuilder builder = new JsonBuilder(content)
content = builder.toPrettyString()


<Script code>
String content = binding.variables.content
JsonSlurper slurper = new JsonSlurper()
def content =  slurper.parse(reader)
assert content


Thanks,

Robert Brooks

From: Guillaume Laforge [glaf...@codehaus.org]
Sent: Friday, October 10, 2014 1:30 AM
To: Groovy User
Subject: Re: [groovy-user] JsonSlurp Lexing failed 1 error; after upgrading the Maven Groovy Eclipse Compiler

Reply all
Reply to author
Forward
0 new messages