Spring-Jersey-Jackson-JSON: Array element wrapped by index -


i'm writing restful service using jersey , jackson de/serialization. i'm using spring dependency injection, i'm using com.sun.jersey.spi.spring.container.servlet.springservlet (not using mvc). i'm using restygwt on client side. i'm returning array of objects service, client complaining not valid json document. here service returning:

   {     "0": {         "type": "aquisition_dt",         "value": "2013-2-1",         "stats": {             "total": 91,             "used": 4         }     },     "1": {         "type": "aquisition_dt",         "value": "2013-1-1",         "stats": {             "total": 24,             "used": 13         }     } } 

i'm not sure, think problem each element wrapped index. there way can instruct jersey or jackson unwrap array elements? please let me know if need provide more info.

in code i'm sending result jsonwithpadding object so: return new jsonwithpadding(array, callback);

btw, i've configured jersey in web.xml use pojo mapping:

<init-param>     <param-name>com.sun.jersey.api.json.pojomappingfeature</param-name>     <param-value>true</param-value> </init-param> 

update did test curl terminal , string returned looks correct (i've removed callback enclosure):

 {     {         "type": "aquisition_dt",         "value": "2013-2-1",         "stats": {             "total": 91,             "used": 4         }     },     {         "type": "aquisition_dt",         "value": "2013-1-1",         "stats": {             "total": 24,             "used": 13         }     } } 

the string posted being reported restygwt. sorry confusing post, i'm not sure why restygwt complaining...

thanks!

if want return array of objects, json format should below

[    {       "type":"aquisition_dt",       "value":"2013-2-1",       "stats":{          "total":91,          "used":4       }    },    {       "type":"aquisition_dt",       "value":"2013-1-1",       "stats":{          "total":24,          "used":13       }    } ] 

you can return array in resource method below

@path("/test") @get         @produces(mediatype.application_json) public test[] haha(){     test[] arr = new test[3];      arr[0] = new test();     arr[1] = new test();     arr[2] = new test();     return arr; } 

where test class below

public class test {     public string type="aquisition_dt";      public string value = "2013-2-1";     public stats stats = new stats(); }  public class stats {     public int total = 10;     public int used = 13; } 

Comments