1

I am trying to get a JSON response when calling the restful service getDocuments http://localhost:8080/httpConnector/Rest/Documents?Accept=application/json

def param = new HashMap();
    String accept = getValue("Accept");
    accept = "application/xml";                
    if ("application/xml".equals(accept)){
        builder=new groovy.xml.MarkupBuilder(writer);
    }else{
        builder=new groovy.json.JsonBuilder();
    }

    builder.'results'() {
        for(FlexiObjectAttachment foa: foaList){
            for(ObjectTypeAttribute ota : otaList){
                param.put(ota.getName(), foa.getFlexiObject().getByString(ota.getName()));

            }
            result(param);
        }       
    }

When Accept = Accept=application/xml I am getting the following response which is the right one:

<results>
    <result content='' author='sdfdsf' description=' description  ' link='21118' name='Dohrn' fileName='' contentType='' version='12.19.00' />
    <result content='' author='ABCD' description=' description  ' link='21119' name='Motor Hour Report' fileName='' contentType='' version='15.25.00' />
    <result content='' author='Alex' description='Test' link='21120' name='Benzin consume' fileName='' contentType='' version='09.55.00' />
</results>

When Accept = Accept=application/json I am getting the following response also here the data of two objects are missing.

{
    "results": {
        "result": {
            "content": "",
            "author": "Alex",
            "description": "Test",
            "link": "21120",
            "name": "Benzin consume",
            "fileName": "",
            "contentType": "",
            "version": "09.55.00"
        }
    }
}

How can I get the whole result as JSON String?

benz
  • 693
  • 1
  • 9
  • 29
  • different cases about jsonbuilder and array discussed here for example: https://stackoverflow.com/questions/28206255/groovy-simple-json-array-builder – daggett May 29 '17 at 12:22

0 Answers0