/**
* Convert the data object into a JSON string Dto object shape such as: {"id": Idvalue, "name": Namevalue, ...}
* Array Object shape such as: [{}, {}, {}, ...] Map object shape: {key1: {"id": Idvalue, "name":
* Namevalue, ...}, Key2: {}, ...}
*
* @param Object
* @return
*/
public static String Getjsonstring (Object object) {
String jsonstring = null;
Property value Processor
Jsonconfig jsonconfig = new Jsonconfig ();
try{
Jsonconfig.registerjsonvalueprocessor (Date.class,new jsondatevalueprocessor ());
Shaping to a string
Jsonconfig.registerjsonvalueprocessor (Integer.class, New Integervalueprocessor ());
if (Object! = null) {
If (object instanceof Collection | | object instanceof object[]) {
jsonstring = Jsonarray.fromobject (object, Jsonconfig)
. toString ();
} else {
jsonstring = Jsonobject.fromobject (object, Jsonconfig)
. toString ();
}
}
} catch (Exception ex) {
Ex.printstacktrace ();
}
return jsonstring = = null? "{}": jsonstring;
}
Object to JSON tool class