My grails 2.2.4 app needs to support accepting files over HTTP from a third party application and sending the file, after making some tweaks to it, back out as a response to the third party application.
I want to convert the data sent by the third party application to a file using InputStream and then send the file back out using OutputStream
So I built this code:
API Classes
class ApiResponse {
    ApiMeta meta
    ApiObject apiObj
}
class ApiMeta {
    int code
    String errorType
    List msgs = []
}
class ApiObject {
    OutputStream os
}
//Object Marshaller
    JSON.registerObjectMarshaller( ApiObject ) { ApiObject obj ->
            //How can I send output stream as json?
    }
Controller
//controller
def save() {
    request.withFormat {
        json {
            ApiResponse resp
            //How can I convert the JSON data in params to a file?
            response.status = 201
            resp = new ApiResponse(
                   meta: new ApiMeta(code: 201), 
                   apiObj: new ApiObject(os: transfers))
            render resp as JSON
        }
     multipartForm {
     }
  }
Question
- How can I convert JSON payload sent by the third party service into a file?
- Is it ok to put OutputStreamin myApiObjectclass so that I can send the JSON payload back to the service?