Jackson configured the Jsonbinder to determine which JSON object to convert,In spring configurationOrg.springframework.http.converter.json.MappingJackson2HttpMessageConverter /*** Create a binder.*/ that outputs all properties to a JSON string publicstaticjsonbinderbuildnormalbinder () { returnnewjsonbinder (inclusion.always);} /*** Create a binder. that only outputs non-empty properties to the
/** * * Next is the Spring Code tool for date and time conversion JSON * * **/ public class Jsondatevalueprocessor Imp Lements jsonvalueprocessor { private String format = "YYYY-MM-DD"; Private String format1 = "HH:mm:ss"; Public Object Processarrayvalue (object value, Jsonconfig config) { return process (value); } Public Object processobjectvalue (String key, Object value, Jsonconfig config) {
Method OneAdd annotations to the properties of the returned entityCreation time@DateTimeFormat (pattern = "Yyyy-mm-dd HH:mm:ss")Private Date CreateDate;Method TwoAnnotate a @initbinder in a controller that uses @responsebody to convert a property in an entity to a date of the data type in JSON formatprivate static final SimpleDateFormat DateFormat = new SimpleDat
JSON Date form: "/date (1242357713797+0800)/", below we will use the following C # method to convert him to a datetime type:The Json date format is converted to a. Net datetime typepublic static DateTime Jsontodatetime (String jsondate){String value = jsondate.substring (6,
JSON Date Format Conversion
1. added the formatting comment for the property getter in bean.Private date uptime; @ jsonserialize (using = jsondateserializer. class) Public date getuptime () {return uptime;} public void setuptime (date uptime) {This. uptime = uptime;} 2. d
Jackson Program: Jackson had a @jsonformat annotation that, after it was configured on the Get method of the date type, Jackson would convert the date type in the configured format, using the type: @JsonFormat (pattern= "Yyyy-mm-dd HH:mm:ss", timezone = "gmt+8") public Date getcreate_date () {return this.createtime;} @JsonFormat (pattern= "Yyyy-mm-dd", timezone =
When newtonsoft. JSON is converted to a date, the format and time zone (8 hours difference) are displayed.
If no format conversion is performed, a date, such as date (1335247957000 + 0800)/, is displayed.
Isodatetimeconverter timeconverter = new isodatetimeconverter (); // The Custom
Step 1: Create the CustomObjectMapper class
/*** Solve the problem that the date format is displayed as a timestamp by default when spring MVC returns json using @ ResponseBody. Cooperation required
Use ** @ author hellostory * @ date 2013-10-31 04:17:52 */@ Component ("plugin") public class extends ObjectMapper {public customObjectMapper () {CustomSerialize
varstr=‘/Date(1333245600000+0800)/‘;functiondata_string(str){vard=eval(‘new‘ +str.substr(1,str.length-2));varar_date=[d.getFullYear(),d.getMonth()+1,d.getDate()];for(vari=0;ireturn ar_date.join(‘-‘);functiondFormat(i){returni"0"+i.toString():i;}}JSON date string format time
/// ///Filter Special Characters/// Private Static stringString2json (String s) {StringBuilder sb=NewStringBuilder (); for(inti =0; i ) { Charc =S.tochararray () [i]; Switch(c) { Case '\"': SB. Append ("\\\""); Break; Case '\\': SB. Append ("\\\\"); Break; Case '/': SB. Append ("\\/"); Break; Case '\b': SB. Append ("\\b"); Break; Case '\f': SB. Append ("\\f"); Break; Case '\ n': SB. Append ("\\n"); Break; Case '\ r': SB. Append ("\\r"); Break; Ca
The default output of time when we use Jackjson is as follows:Output is a string of time stamps, do not meet our requirements, so think of Jackjson on the processing of time has his default format, and then collect all kinds of information on the Internet, to get a way to solveTo cancel the format of Jackjson default processing time:FALSE);The time format for the output after Setup is "1970-01-01t00:00:00.000+0000".We can customize the time format:SimpleDateFormat mydateformat=New SimpleDateForm
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.