longwa opened a new issue, #14275:
URL: https://github.com/apache/grails-core/issues/14275

   When calling `response.json` in a Specification to test a RestfulController 
that `respond` with an empty list, an error occurs if you have created a 
default `/object/_object.gson` view such as:
   
   ```
   model {
       Object object
   }
   json g.render(object)
   ```
   
   Condition failed with Exception:
   
   ```
   response.json.size() == 0
   |        |
   |        org.grails.web.converters.exceptions.ConverterException: Error 
parsing JSON
   |            at grails.converters.JSON.parse(JSON.java:260)
   |            at 
org.grails.plugins.testing.AbstractGrailsMockHttpServletResponse.getJson(AbstractGrailsMockHttpServletResponse.groovy:93)
   |            at example.FooControllerSpec.test 
something(FooControllerSpec.groovy:20)
   |        Caused by: org.grails.web.json.JSONException: Missing value. at 
character 0 of 
   |            at 
org.grails.web.json.JSONTokener.syntaxError(JSONTokener.java:481)
   |            at 
org.grails.web.json.JSONTokener.nextValue(JSONTokener.java:358)
   |            at grails.converters.JSON.parse(JSON.java:251)
   |            ... 2 more
   <org.grails.plugins.testing.GrailsMockHttpServletResponse@379efd4e 
outputStreamAccessAllowed=true writerAccessAllowed=true 
characterEncoding=ISO-8859-1 charset=false content= 
outputStream=org.springframework.mock.web.MockHttpServletResponse$ResponseServletOutputStream@18b06b
 writer=null contentLength=0 contentType=application/json bufferSize=4096 
committed=false locale=en_US cookies=[] 
headers=[Content-Type:[application/json]] status=200 errorMessage=null 
forwardedUrl=null includedUrls=[]>
   ```
   
   Without the default GSON view, it works ok.
   
   If you change the grails version to 4.0.5, the test will pass successfully, 
so this seems to be a regression in 4.0.6.
   
   ### Task List
   
   - [x] Steps to reproduce provided
   - [x] Stacktrace (if present) provided
   - [x] Example that reproduces the problem uploaded to Github
   - [x] Full description of the issue provided (see below)
   
   ### Steps to Reproduce
   Download the sample application and run:
   
   - git clone https://github.com/longwa/grails-gson-view-issue
   - gradle test
   
   The key is to call respond for a JSON format without an explicit GSON view 
to render.
   
   ### Expected Behaviour
   
   `response.json` should succeed and essentially return empty (size == 0) as 
it does in 4.0.5.
   
   ### Actual Behaviour
   
   An error occurs when `JSON.parse()` is called b/c the output stream has an 
empty string instead of empty array syntax: `""` vs `"[]"`. This seems to be a 
result of the `_object.gson` being used, which causes the renderer to follow a 
different path.
   
   ### Environment Information
   
   - **Operating System**: macOS 10.15.7
   - **Grails Version:** 4.0.6
   - **JDK Version:** zulu-1.8_275
   
   ### Example Application
   
   - https://github.com/longwa/grails-gson-view-issue
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to