1

I have a controller function that returns a list datatype that gets converted to JSON once sent back to my jQuery.

My problem (well not really a problem) is that the data return has no field names and I would prefer them to have the field names.

I found some post here that involves configuring jackson but it seems it's a global setting. I only want some functions to return named fields.

Can you please help? thanks

my controller function

@RequestMapping(value = "/GetEvents", method = RequestMethod.GET, headers="Accept=*/*")
public @ResponseBody List<Session> getEvents(@RequestParam("description") String description) {
    List<Session> temp = issuService.getEvents(description);

    return temp;
}

data return by function (as viewed in firebug)

[[1149,"Thursday , 31 January   2013 @ 13:00 - 15:00",1,"2013-01-31"],[1150,"Wednesday, 06 February  2013 @ 13:00 - 15:00",1,"2013-02-06"],[1151,"Wednesday, 13 February  2013 @ 13:00 - 15:00",1,"2013-02-13"],[1152,"Monday   , 18 February  2013 @ 13:00 - 15:00",1,"2013-02-18"],[1169,"Wednesday, 20 February  2013 @ 13:00 - 15:00",1,"2013-02-20"],[1170,"Monday   , 25 February  2013 @ 13:00 - 15:00",1,"2013-02-25"],[1171,"Tuesday  , 26 February  2013 @ 13:00 - 15:00",1,"2013-02-26"],[1172,"Wednesday, 27 February  2013 @ 13:00 - 15:00",1,"2013-02-27"],[1173,"Thursday , 28 February  2013 @ 13:00 - 15:00",1,"2013-02-28"],[1174,"Friday   , 01 March     2013 @ 13:00 - 15:00",1,"2013-03-01"]]
mrjayviper
  • 2,258
  • 11
  • 46
  • 82
  • Yes, it would need a global configuration for Jackson. For your requirement, you can use a wrapper object to wrap your Session object – gouki Jan 11 '13 at 09:01

1 Answers1

0

Format of your data returned by controller seems like an array.and not valid json format.

Refer to this post Spring configure @ResponseBody JSON format

asking the same question.

Community
  • 1
  • 1
Sangeeta
  • 164
  • 4
  • 16
  • I forgot to add in my original post that I saw that same discussion but looking at it, it seems a global setting. I want only some of my functions to return named fields. thanks again! :) – mrjayviper Jan 11 '13 at 04:22