When you use Json-lib to convert a Java.util.Date object directly into a JSON string, you usually get a format that is not what you want:
System.out.println (Jsonserializer.tojson (new Date () )); // {"Date": +, "Day": 3, "hours": minutes, "month": 5, "Seconds": $, "time": 1435120786584, "Timezoneoffset":- 480, "Year":
JavaBean Turn JSON
Jsonvalueprocessor Jsonvalueprocessor =Newjsonvalueprocessor () {Private FinalString date_format = "Yyyy-mm-dd"; @Override PublicObject Processobjectvalue (String key, object value, Jsonconfig config) {if(Value = =NULL) { return""; } if(ValueinstanceofDate) { return NewSimpleDateFormat (date_format). FORMAT ((DATE) value); } returnvalue.tostring (); } @Override PublicObject Processarrayvalue (object value, Jsonconfig config) {return NULL; }}; Jsonconfig Jsonconfig=Newjsonconfig (); Jsonconfig.registerjsonvalueprocessor (Date.class, Jsonvalueprocessor); Student Stud=NewStudent ("1001", "Huey", ' M ',NewDate ()); String Jsonstr=Jsonserializer.tojson (Stud, jsonconfig). toString (); System.out.println (JSONSTR); //{"Birthday": "2015-06-24", "Gender": "M", "Studname": "Huey", "Studno": "1001"}
JSON Turn JavaBean
String jsonstr = "{' Studno ': ' 1001 ', ' Studname ': ' Huey ', ' Gender ': ' M ', ' Birthday ': ' 2014-04-13 '}"= Jsonobject.fromobject (JSONSTR); Jsonutils.getmorpherregistry (). Registermorpher (new datemorpher (new string[]{"Yyyy-mm-dd" = (Student) Jsonobject.tobean (Jsonobj, Student. Class); SYSTEM.OUT.PRINTLN (stud); // Student (studno=1001, Studname=huey, gender=m, Birthday=sun Apr 00:00:00 CST)
JavaBean definition
@Data @noargsconstructor@allargsconstructor Public class Student { private String studno; Private String studname; Private Char gender; Private Date birthday; }
Json-lib-java.util.date Conversion Issues