Json parsing error thrown while running the service consumer test
See original GitHub issueHey guys,
We have a pact-jvm(pact-jvm-consumer-junit_2.11:3.4.1) setup running the junit tests to generate the pact file.Recently we have started getting this error while running the tests. Stacktrace doesnt give a lot of info but looks like some discrepancy in reading the Pact file. Not sure if its how I am generating the response causing the issue.
groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object
The current character read is '?' with an int value of 0
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 255
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
...............................................................................................................................................................................................................................................................^
at groovy.json.internal.JsonParserCharArray.decodeValueInternal(JsonParserCharArray.java:206)
at groovy.json.internal.JsonParserCharArray.decodeValue(JsonParserCharArray.java:157)
at groovy.json.internal.JsonParserCharArray.decodeFromChars(JsonParserCharArray.java:46)
at groovy.json.internal.JsonParserCharArray.parse(JsonParserCharArray.java:384)
at groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:128)
at groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:151)
at groovy.json.JsonSlurper.parseFile(JsonSlurper.java:365)
at groovy.json.JsonSlurper.parse(JsonSlurper.java:348)
at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:232)
at au.com.dius.pact.model.PactReader.loadFile(PactReader.groovy:159)
at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:232)
at au.com.dius.pact.model.PactReader.loadPact(PactReader.groovy:26)
at au.com.dius.pact.model.PactReader.loadPact(PactReader.groovy)
at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:232)
at au.com.dius.pact.model.BasePact.write(BasePact.groovy:109)
at au.com.dius.pact.consumer.BaseMockServer.runAndWritePact(MockHttpServer.kt:147)
at au.com.dius.pact.consumer.ConsumerPactRunnerKt.runConsumerTest(ConsumerPactRunner.kt:13)
at au.com.dius.pact.consumer.BaseProviderRule.runPactTest(BaseProviderRule.java:148)
at au.com.dius.pact.consumer.BaseProviderRule.access$100(BaseProviderRule.java:21)
at au.com.dius.pact.consumer.BaseProviderRule$1.evaluate(BaseProviderRule.java:76)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:114)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:57)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:66)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:377)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
This is one of the interaction setup where we are getting this error,
@Pact(consumer = CONSUMER_ID)
public RequestResponsePact getBoardsForMobile(PactDslWithProvider builder) {
return builder
.given("Project with boards")
.uponReceiving("GET all boards")
.matchPath(BOARDS_API_PATTERN, BOARDS_API_EXAMPLE)
.method("GET")
.query("maxResults=10")
.willRespondWith()
.status(HttpStatus.SC_OK)
.headers(ImmutableMap.of("Content-Type", "application/json"))
.body(new PactDslJsonBody()
.minArrayLike("values", 1)
.id()
.stringMatcher("type", "CORE")
.stringMatcher("name", "Business")
.stringMatcher("moduleKey", CORE_MODULE_EXAMPLE)
.closeObject()
.object()
.id()
.stringMatcher("type", "SCRUM")
.stringMatcher("name", "DEMO board")
.stringMatcher("moduleKey", AGILE_MODULE_EXAMPLE)
.closeObject()
.closeArray()
.asBody())
.toPact();
}
And this is how the json from pact file looks like,
mobile-rest-plugin will respond with:
{
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"values": [
{
"name": "Business",
"id": 8124081232,
"type": "CORE",
"moduleKey": "core-mobile-board-service"
},
{
"name": "DEMO board",
"id": 4597649782,
"type": "SCRUM",
"moduleKey": "agile-mobile-board-service"
}
]
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:17 (7 by maintainers)
Top Results From Across the Web
Error while parsing JSON Response in REST API Post call
I have copied and pasted the REST Request and Response JSON definitions into the Request and Response text boxes provided by OS REST...
Read more >Json Parsing error - MSDN - Microsoft
When I run my code, I am getting error as- After parsing a value an unexpected character was encountered: P. Path 'Rows[1253].
Read more >Trouble with parsing JSON result from REST - ServiceNow
I'm getting results back, but when I try to parse them using the JSON parser, the whole thing stops working (even the REST...
Read more >java - JSON parse error: Cannot deserialize instance of `` out ...
My general idea is to get data from public API store it on the local database and then use those data according to...
Read more >SyntaxError: JSON.parse: bad parsing - LambdaTest
However just like any programming language, it throws a lot of errors when it decide that today is not going to be your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Version 3.5.2 has been released with synchronisation and file locking on the pact file.
I definitely need to put that synchronisation check in before writing the pact file.