JSON series four uncover Jsonconfig's mystery Java to JSON

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.