sahaya / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

Json: prettyPrint() throws exception for HashMap #218

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. I try to use prettyPrint() method for Json file that looks like this:

{
   "data": [
      {
         "uid": 10,
         "name": "abc"
      }
   ]
}

What is the expected output? What do you see instead?

java.lang.NullPointerException: Cannot invoke method isArray() on null object.

[org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77),
org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.ja
va:45),
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.jav
a:42),
org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32),
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.jav
a:42),
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java
:108),
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java
:112),
groovy.json.JsonOutput.toJson(JsonOutput.groovy:115),
com.jayway.restassured.path.json.JsonPath.prettify(JsonPath.java:555),
com.jayway.restassured.path.json.JsonPath.prettyPrint(JsonPath.java:564),

What version of the product are you using? On what operating system?
Rest-Assured 1.7.2

Please provide any additional information below.
I suppose the reason is that JsonPath for this is represented by HashMap ( json 
= {java.util.HashMap}   {data=[{uid=10, name=abc}]} ).
So in prettify() method JsonOutput.toJson(json) is called, then in this part of 
the code

 } else if (object instanceof Collection ||
                object.class.isArray() ||

object.class returns null because it is HashMap 
(http://groovy.codehaus.org/FAQ+-+Collections,+Lists,+etc.#FAQ-CollectionsListse
tc-WhydoesmyMapsizeormyMapclassreturnnull - maybe explanation here?)

Original issue reported on code.google.com by ir.tim....@gmail.com on 27 Feb 2013 at 9:11

GoogleCodeExporter commented 9 years ago
Could you please try and see if you get the same error in the 1.8.0 release?

Original comment by johan.ha...@gmail.com on 16 Apr 2013 at 1:37

GoogleCodeExporter commented 9 years ago
Yes, tried with 1.8 and got the same error.

Original comment by ir.tim....@gmail.com on 25 Apr 2013 at 12:59

GoogleCodeExporter commented 9 years ago
Alright, I'll accept the issue.

Original comment by johan.ha...@gmail.com on 26 Apr 2013 at 11:15

GoogleCodeExporter commented 9 years ago
This has now been fixed in master. Thanks you for reporting.

Original comment by johan.ha...@gmail.com on 14 May 2013 at 7:13