The Java object is converted to JSON format by Jackson, and the first letter of the property name becomes a lowercase solution

Source: Internet
Author: User

Java code objects are as follows:

Package com.evideostb.billsystem.module.model;import org.codehaus.jackson.map.annotate.jsonserialize ;import com.fasterxml.jackson.annotation.jsonignore;import  com.fasterxml.jackson.annotation.jsonproperty;/** *  response protocol Header  *  @author  zhangchuanzhao  * 2015-9-18 pm 3:12:58 */@JsonSerialize (include=jsonserialize.inclusion.non_null) public  class responseprotocol {//Error number:0  success &NBSP, other indicates failure protected string errorcode;// Tip Error Message protected string errormessage;//exception error message protected string exceptmessage;/** *   Get error number:0  success &NBSP, other represents failure  *  @return  */public string geterrorcode ()  { Return errorcode;} /** *  Set error number:0  success &NBSP, other indicates failure  *  @param  errorCode */public void  Seterrorcode (String errorcode)  {this. Errorcode = errorcode;} /** *  getting prompt error messages  *  @return  */public string geterroRmessage ()  {return errormessage;} /** *  set prompt error message  *  @param  errormessage */public void seterrormessage ( String errormessage)  {this. Errormessage = errormessage;} /** *  Get exception error message  *  @return  */public string getexceptmessage ()  {return  exceptmessage;} /** *  Setting exception error messages  *  @param  exceptmessage */public void setexceptmessage ( String exceptmessage)  {this. Exceptmessage = exceptmessage;}}

If the above object is converted to JSON format by Jackson, the initial letter will automatically become lowercase, what if I want to capitalize the first letter?

in the attribute is added @JsonProperty annotation, and in the corresponding setter, getter above plus @jsonignore, so you can, add the following code as follows:

Package com.evideostb.billsystem.module.model;import org.codehaus.jackson.map.annotate.jsonserialize ;import com.fasterxml.jackson.annotation.jsonignore;import  com.fasterxml.jackson.annotation.jsonproperty;/** *  response protocol Header  *  @author  zhangchuanzhao  * 2015-9-18 pm 3:12:58 */@JsonSerialize (include=jsonserialize.inclusion.non_null) public  class responseprotocol {//Error number:0  success &NBSP, other indicates failure @jsonpropertyprotected string  errorcode;//Tip Error Message @jsonpropertyprotected string errormessage;//exception error message @jsonpropertyprotected  string exceptmessage;/** *  get error number:0  success &NBSP, other indicates failure  *  @return  */@ Jsonignorepublic string geterrorcode ()  {return errorcode;} /** *  Set error number:0  success &NBSP, other indicates failure  *  @param  errorcode */@JsonIgnorepublic   Void seterrorcode (String errorcode)  {this. Errorcode = errorcode;} /** *  getting prompt errorInformation  *  @return  */@JsonIgnorepublic  string geterrormessage ()  {return  ErrorMessage;} /** *  Setup prompt error message  *  @param  errormessage */@JsonIgnorepublic  void  Seterrormessage (string errormessage)  {this. Errormessage = errormessage;} /** *  Get exception error message  *  @return  */@JsonIgnorepublic  string getexceptmessage ()  {return exceptmessage;} /** *  Setting exception error messages  *  @param  exceptmessage */@JsonIgnorepublic  void  Setexceptmessage (string exceptmessage)  {this. Exceptmessage = exceptmessage;}}
{"ErrorCode": "0", "responseinfo": [{"Roomsubjectname": "All Topics", "Roomsubjectid": "1"},{"Roomsubjectname": "European Style", " Roomsubjectid ":" 1 "}]}


The Java object is converted to JSON format by Jackson, and the first letter of the property name becomes a lowercase solution

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.