JSON Single row, not picked up by datatables or ignored.
JSON Single row, not picked up by datatables or ignored.
Dabbo07
Posts: 3Questions: 0Answers: 0
Hi, I'm having trouble understanding why dataTables is refusing to show a single row of data but it works perfectly fine for any data sets greater than 1 row. My debugger ID is 'ezunup' - I don't think this shows the issue either, as I think it's the format of the JSON message at fault here - The responses I captured were :
This is a 10 record JSON response which works OK:
[code]{"eventRetryLog":[{"eventstatus":"30","publisheventnumber":"102","retrycount":"0","retrymaximumcount":"10","retrytime":"14:54:19 20/02/12"},{"eventstatus":"30","publisheventnumber":"103","retrycount":"0","retrymaximumcount":"10","retrytime":"14:54:28 20/02/12"},{"eventstatus":"19","publisheventnumber":"125","retrycount":"10","retrymaximumcount":"10","retrytime":"15:22:53 20/02/12"},{"eventstatus":"19","publisheventnumber":"126","retrycount":"10","retrymaximumcount":"10","retrytime":"15:23:03 20/02/12"},{"eventstatus":"19","publisheventnumber":"127","retrycount":"10","retrymaximumcount":"10","retrytime":"15:24:19 20/02/12"},{"eventstatus":"19","publisheventnumber":"128","retrycount":"10","retrymaximumcount":"10","retrytime":"15:24:25 20/02/12"},{"eventstatus":"30","publisheventnumber":"148","retrycount":"0","retrymaximumcount":"10","retrytime":"17:26:13 20/02/12"},{"eventstatus":"19","publisheventnumber":"155","retrycount":"10","retrymaximumcount":"10","retrytime":"11:25:19 21/02/12"},{"eventstatus":"30","publisheventnumber":"165","retrycount":"0","retrymaximumcount":"10","retrytime":"11:41:46 21/02/12"},{"eventstatus":"19","publisheventnumber":"245","retrycount":"10","retrymaximumcount":"10","retrytime":"12:59:24 12/04/12"}],"iTotalDisplayRecords":"10","iTotalRecords":"10","sEcho":"1"} [/code]
This is a single row JSON response which display's "No matching records found":
[code] {"eventRetryLog":{"eventstatus":"30","publisheventnumber":"102","retrycount":"0","retrymaximumcount":"10","retrytime":"14:54:19 20/02/12"},"iTotalDisplayRecords":"1","iTotalRecords":"1","sEcho":"2"} [/code]
I've noticed there isn't a square bracket around the data on the single row data - so the elements merge into the tailing dataTable parameters. I'm not great with my JSON configuration so I'm kind of hoping to fix this on the dataTables side.
If it is a JSON formatting issue, any hints to help me fix it would be appreciated. I'm using Jersey v1.5 if this if relevant.
Many thanks in advance,
Darren.
This is a 10 record JSON response which works OK:
[code]{"eventRetryLog":[{"eventstatus":"30","publisheventnumber":"102","retrycount":"0","retrymaximumcount":"10","retrytime":"14:54:19 20/02/12"},{"eventstatus":"30","publisheventnumber":"103","retrycount":"0","retrymaximumcount":"10","retrytime":"14:54:28 20/02/12"},{"eventstatus":"19","publisheventnumber":"125","retrycount":"10","retrymaximumcount":"10","retrytime":"15:22:53 20/02/12"},{"eventstatus":"19","publisheventnumber":"126","retrycount":"10","retrymaximumcount":"10","retrytime":"15:23:03 20/02/12"},{"eventstatus":"19","publisheventnumber":"127","retrycount":"10","retrymaximumcount":"10","retrytime":"15:24:19 20/02/12"},{"eventstatus":"19","publisheventnumber":"128","retrycount":"10","retrymaximumcount":"10","retrytime":"15:24:25 20/02/12"},{"eventstatus":"30","publisheventnumber":"148","retrycount":"0","retrymaximumcount":"10","retrytime":"17:26:13 20/02/12"},{"eventstatus":"19","publisheventnumber":"155","retrycount":"10","retrymaximumcount":"10","retrytime":"11:25:19 21/02/12"},{"eventstatus":"30","publisheventnumber":"165","retrycount":"0","retrymaximumcount":"10","retrytime":"11:41:46 21/02/12"},{"eventstatus":"19","publisheventnumber":"245","retrycount":"10","retrymaximumcount":"10","retrytime":"12:59:24 12/04/12"}],"iTotalDisplayRecords":"10","iTotalRecords":"10","sEcho":"1"} [/code]
This is a single row JSON response which display's "No matching records found":
[code] {"eventRetryLog":{"eventstatus":"30","publisheventnumber":"102","retrycount":"0","retrymaximumcount":"10","retrytime":"14:54:19 20/02/12"},"iTotalDisplayRecords":"1","iTotalRecords":"1","sEcho":"2"} [/code]
I've noticed there isn't a square bracket around the data on the single row data - so the elements merge into the tailing dataTable parameters. I'm not great with my JSON configuration so I'm kind of hoping to fix this on the dataTables side.
If it is a JSON formatting issue, any hints to help me fix it would be appreciated. I'm using Jersey v1.5 if this if relevant.
Many thanks in advance,
Darren.
This discussion has been closed.
Replies
Allan
Allan
Thank you for the prompt response - I'll have a look into overriding the Jersey method(s) to correctly format the message - failing that, I'll look at your second suggestion :D
I'll post a solution when I get to it just in case someone else encounters a similar problem.
Thanks again and great plug-in btw ;)
Darren.
Apparently, my application's web.xml didn't specify a provider (which is OK) and it would default to using "JAXB JSON" and we need to use "Jackson" - I have no idea, but it worked by adding the following class path to my web.xml ...
[code]
com.sun.jersey.config.property.packages
your.project.packages;org.codehaus.jackson.jaxrs
[/code]
Added : "org.codehaus.jackson.jaxrs" to the init-param section.
For a better explanation, please refer to the original source:
Reference : http://stackoverflow.com/questions/2199453/how-can-i-customize-serialization-of-a-list-of-jaxb-objects-to-json/3143214#3143214
Thanks, Darren.