Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8385753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:45:03+00:00 2026-06-09T17:45:03+00:00

I have a Spring controller method that is correctly returning a collection of objects

  • 0

I have a Spring controller method that is correctly returning a collection of objects in the JSON to the client:

@RequestMapping(value="/admin/rawreads/unknowntags", method=RequestMethod.GET)
public @ResponseBody Collection<RawRead> getRawReadsWithUnknownTag() {
    ....
}

I’m trying to integrate a jQuery addon/plugin called DataTables. DataTables can handle the asynchronous request to fetch data and populate a table in the page for me, however it requires the data to be return in an array with a specific name “aaData” rather than the current format of :

[{"oid":149452,"date":1233076733000,"readerId":"811210008","recordNo":226,"tagCode":"0103A003C0","reader":null,"guard":null,"checkpoint":null},{"oid":149453,"date":1233076734000,"readerId":"8112100 .... etc]

Suggested return format for DataTables from the DataTable docs:

{
 "sEcho": 1,
 "iTotalRecords": "n",
 "iTotalDisplayRecords": "n",
 "aaData": [
 [object1][object2].... etc
 ]
}

How can I change my Java method to return data in the format DataTables needs – a named array?

EDIT:
Tried putting vars into a HashMap serverside, gets a bit closer to what I need:

{"iTotalDisplayRecords":3050,"iTotalRecords":3050,"aaData":   
  [{"oid":149452,"date":1233076733000, ...<snip>},{...}]
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:45:05+00:00Added an answer on June 9, 2026 at 5:45 pm

    Make a separate class in the correct format for data tables, having fields for sEcho, itotalrecords, ittotaldisplayrecords and then an array called aaData.

    Then return this class via jason and that is then in your suggested format.

    class TableDTO
    {
     int sEcho;
     int iTotalRecords;
     int itotalDisplayRecords;
    
     array[] aaData;
    }
    

    Obviously assign data to these fields and proper accessors etc!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a spring action that I am rendering some json from the controller,
I have a Spring controller that returns XHTML, what's the easiest way to setup
I have a controller (Spring-MVC) that generates a PDF report on a get request.
I have @Controller @RequestMapping(value=core/*) public class CoreController { public static String exceptionOccurredView = /core/exceptionOccurred;
I have controller method in my MVC application that I am calling using the
I have a controller POST action that redirects to a GET method using RedirectToAction.
First I have a Spring 3.0 controller with a method similar to the following.
I have a situation where I'm returning json objects to my application which are
In my spring config file I have <global-method-security pre-post-annotations=enabled/> In my spring @Controller I
How do I correctly use RESTful delete in Spring MVC controller? I have DAO

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.