New to java, but would love to implement my working jsp that generates xml used by a lovely jquery flexigrid to use a json version (generated by gson). I’m just starting out w/ java basically, but would like to learn the best way to do this. I’ve been looking at inner classes, but wanted to check out what would be considered best practice.
The json expected format (I got this from another post here) is:
total: (no of rec)
page : (page no)
rows : {id: 1, cell: [ (col1 value) , (col2 value) ,.. ] },
{id: 2, cell: [ (col1 value) , (col2 value) ,.. ] }
And, so far my non compilable java is:
private class _JsonReturn {
int page ;
int total ;
class Rows {
String id = new String();
MultiMap cell = new MultiValueMap() ;
private Rows( String newCell ) {
this.id = newCell ;
}
private void _addRowValue( String cellValue ){
this.cell.put( this.id, cellValue );
}
private Object _getRows() {
return this ;
}
}
}
Help – I think I’m over complicating things here! Thanks a ton in advance!
Xstream is a very handly and useful library to marshall java classes or POJO to xml or json. And it also very fast.
EDIT
For your java structure requeriments, I propose you a simple structure (perhaps I get a -1, but it’s the simplest 🙂
Then you can parse it with any JsonParser.
I hope it helps you 🙂