First you need to download package: jackson-databind-2.0.5.jarjackson-annotations-2.0.5.jarjackson-core-2.0.5.jar, URL in: http://wiki.fasterxml.com/JacksonDownload
Custom. JSON:
{
"Country": "USA ",
"Countryinfo": {"golden": 40, "Silver": 23, "copper": 33, "tank": 1 },
"Countrydetail ":[
{"ID": "no", "Header": "Number", "fieldindex": "no", "sortorder": NULL, "printable": true },
{"ID": "name", "Header": "name", "fieldindex": "name", "sortorder": NULL, "printable": true },
{"ID": "Total", "Header": "total score", "fieldindex": "Total", "sortorder": NULL, "printable": true },
{"ID": "detail", "Header": "details", "fieldindex": "detail", "sortorder": NULL, "printable": true}
],
"Orgood": true}
Java Bean and parsing:
Import java. Io. file;
Import java. Io. ioexception;
Import com. fasterxml. Jackson. Core. jsonparseexception;
Import com. fasterxml. Jackson. databind. jsonmappingexception;
Import com. fasterxml. Jackson. databind. objectmapper;
Public class bean {
Private string country;
Private Boolean orgood;
Private country countryinfo;
Private countrydetail [] countrydetail;
Public String getcountry (){
Return country;
}
Public void setcountry (string country ){
This. Country = Country;
}
Public Boolean isorgood (){
Return orgood;
}
Public void setorgood (Boolean orgood ){
This. orgood = orgood;
}
Public Country getcountryinfo (){
Return countryinfo;
}
Public void setcountryinfo (country countryinfo ){
This. countryinfo = countryinfo;
}
Public countrydetail [] getcountrydetail (){
Return countrydetail;
}
Public void setcountrydetail (countrydetail [] countrydetail ){
This. countrydetail = countrydetail;
}
Public static class country {
Public String getgolden (){
Return golden;
}
Public void setgolden (string golden ){
This. Golden = golden;
}
Public String getsilver (){
Return silver;
}
Public void setsilver (string silver ){
This. Silver = silver;
}
Public String getcopper (){
Return copper;
}
Public void setcopper (string copper ){
This. Copper = copper;
}
Public String gettank (){
Return tank;
}
Public void settank (string tank ){
This. tank = tank;
}
Private string golden;
Private string silver;
Private string copper;
Private string tank;
}
Public static class countrydetail {
Public String GETID (){
Return ID;
}
Public void setid (string ID ){
This. ID = ID;
}
Public String getheader (){
Return header;
}
Public void setheader (string header ){
This. header = header;
}
Public String getfieldindex (){
Return fieldindex;
}
Public void setfieldindex (string fieldindex ){
This. fieldindex = fieldindex;
}
Public String getsortorder (){
Return sortorder;
}
Public void setsortorder (string sortorder ){
This. sortorder = sortorder;
}
Public Boolean isprintable (){
Return printable;
}
Public void setprintable (Boolean printable ){
This. printable = printable;
}
Private string ID;
Private string header;
Private string fieldindex;
Private string sortorder;
Private Boolean printable;
}
Public static void main (string ARGs []) {
Objectmapper mapper = new objectmapper ();
Try {
Bean = Mapper. readvalue (new file ("custom. JSON"), Bean. Class );
// Read
System. Out. println ("Country:" + bean. getcountry ());
System. Out. println ("countryinfo:" + bean. getcountryinfo (). getgolden ());
System. Out. println ("countrydetail:" + bean. getcountrydetail () [1]. getheader ());
System. Out. println ("orgood:" + bean. isorgood ());
} Catch (jsonparseexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (jsonmappingexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (ioexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
}