Uncover Jsonconfig's mystery, for beans to json jsonconfig jsonconfig = new Jsonconfig (); Ignoring the field of a post with a note in the bean and not converting it to JSON, you can add different annotations//jsonconfig.addignorefieldannotation (Person.class) multiple times;//must be a class of annotations, I do not have an example here, we can do their own//ditto//jsonconfig.addignorefieldannotation ("person"); Converts a type of class to a custom result Jsonconfig.registerdefaultvalueprocessor (Address.class, New Defaultvalueprocessor () {@ Overridepublic Object getdefaultvalue (Class type) {return null;}}); Return to your own set of jsonobject//Jsonconfig.registerjsonbeanprocessor (Person.class, New Jsonbeanprocessor () {////@Override// Public Jsonobject Processbean (Object Bean, Jsonconfig jsonconfig) {////return null;//}//});// Jsonconfig.registerpropertynameprocessor (target, propertynameprocessor);//Replaced by registerjsonpropertynameprocessor /In the JSON layer when the conversion, than the above javapropertyname to perform jsonconfig.registerjsonpropertynameprocessor (Person.class, new Propertynameprocessor () {@Overridepublic string processpropertyname (Class beanclass, string name) {if (Name.equals (" Name ") {return" Namejson ";} Return Name;} }); Jsonconfig.registerjsonvalueprocessor (String.class, New Jsonvalueprocessor () {@Overridepublic Object in JSON layer conversion Processobjectvalue (String key, Object value,jsonconfig jsonconfig) {if (Key.equals ("EmptyStr")) {return ' ASDFA ';} return value;} @Overridepublic Object Processarrayvalue (object value, Jsonconfig jsonconfig) {//TODO auto-generated method Stubreturn N ull;} }); Jsonconfig.registerjsonvalueprocessor ("Nullstr", new Jsonvalueprocessor () {@Overridepublic Object Processobjectvalue (String key, Object value,jsonconfig jsonconfig) {return ' nullStr2 ';} @Overridepublic Object Processarrayvalue (object value, Jsonconfig jsonconfig) {return null;}}); /jsonconfig.registerjsonvalueprocessor (Beanclass, PropertyType, jsonvalueprocessor);//More Refinement// Jsonconfig.registerjsonvalueprocessor (Beanclass, Key, jsonvalueprocessor)//More detailed// which attribute jsonconfig.registerpropertyexclusion (Person.class, "sametest") is excluded; Jsonconfig.registerpropertyexclusions (target, properties);//Whether empty Jsonconfig.setallo is allowedWnonstringkeys (TRUE);//Internal if there is a nested reference, how to handle default_cycle_detection_strategy = cycledetectionstrategy.strict;// Jsonconfig.setcycledetectionstrategy (cycledetectionstrategy);//Can be achieved bar a class converted to B class// Jsonconfig.setdefaultvalueprocessormatcher (New Defaultvalueprocessormatcher () {////@Override//public Object Getmatch (Class target, set set) {////return B.class//return null;//}//});//Ignore which properties//jsonconfig.setexcludes (excludes) ;//jsonconfig.setignoredefaultexcludes (ignoredefaultexcludes);//jsonconfig.setignorejpatransient ( ignorejpatransient);//jsonconfig.setignorepublicfields (ignorepublicfields);// Jsonconfig.setignoretransientfields (Ignoretransientfields);//jsonconfig.setjsonvalueprocessormatcher ( Jsonvalueprocessormatcher);//jsonconfig.setjsonpropertynameprocessormatcher (Propertynameprocessormatcher); Jsonconfig.setjsonpropertyfilter (New PropertyFilter () {@Overridepublic Boolean apply (Object source, String name, Object value) {//TODO auto-generated method Stubreturn false;}}); /jsonconfig.setjsonbEanprocessormatcher (Jsonbeanprocessormatcher);//jsonconfig.setjavascriptcompliant (javascriptCompliant); SYSTEM.OUT.PRINTLN (Format (Jsonobject.fromobject (P, jsonconfig). toString ()));
JSON series four uncover Jsonconfig's mystery Java to JSON