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