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 out
Resources:http://blog.csdn.net/remote_roamer/article/details/51330843http://blog.csdn.net/xiaodaiye/article/details/51118870In Spring-data-jpa, One-to-many and many-to-one annotations were used, and an error occurred while JSON was being serialized.The following solutions have been found through the data access:Annotate the associated fields by adding @jsonmanagedreference to the pojo of the main table:@OneToMany (cascade = Cascadetype.refresh, mapped
(student);Print out the results:Student [name=king, age=21, position=null, createTime=null]General operations: object to String student.setCreateTime(new Date()); String json = mapper.writeValueAsString(student); System.out.println(json);Print out the results:{"name":"king","age":21,"position":null,"createTime":1524819355361}How do I change the format of the Output date field?Two ways:
-missing issues when converting from string JSON to type. Like what Case class = Mapper.readvalue ("{}", Classof[demo]) println (Demo)Demo (false,0,null,0.0)In case of Spray.json occurrence key missing, it will exceptionAnd for the domain key there is a redundant situationJackson ErrorVal demo1 = Mapper.readvalue ("{\" x\ ": true, \" y\ ": 1100, \" c\ ": \" str\ ", \" d\ ": \" Str\ "}", CLA Ssof[demo])Spray.json is no problem.There is no relationship
;} /*** Get exception error message * @return */publicstringgetexceptmessage () {return exceptmessage;} /*** Setting exception error messages * @param exceptmessage*/publicvoidsetexceptmessage ( Stringexceptmessage) {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 l
BackgroundA clean spring+spring mvc+mybatis frame is required, and the framework writes the error to the return JSON link.ProblemCan't json, quote 406SolveNeed to configure the JSON toolkit, here with JacksonMaven JacksonEngineering Environment SPRINGMVC 4.x, incompatible with Jackson2.9 latest version. Here Special Application 2.6 versionSpring MVC Configuration
Use Jackson to parse a good JSON file here:
Http://sarin.iteye.com/blog/821534
The core part is as follows:Try {Jsonfactory = new mappingjsonfactory ();// JSON parserJsonparser = jsonfactory. createjsonparser (jsontext );// Jump to the start of the result setJsonparser. nexttoken ();// Hashmap that accepts the resultHashmap // While loop traverses the
Spring-data-jpa -- if one-to-one and others-to-one annotations are used, an error solution will appear during Jackson's json String Conversion,
References:
Http://blog.csdn.net/remote_roamer/article/details/51330843
Http://blog.csdn.net/xiaodaiye/article/details/51118870
In spring-data-jpa, one-to-one and two-to-one annotations are used to produce json strings.
Find the following solutions after readin
Ext.: http://www.cnblogs.com/quanyongan/archive/2013/04/16/3024993.htmlJackson, I feel like the fastest framework for converting between Java and JSON, and of course Google's Gson is good, but it looks like Jackson's faster than anyone else's performance test on the web.Jackson handles the conversion between the general JavaBean and JSON as long as the ReadValue and writevalueasstring two methods using the
Jackson JSON and objects, several transformations of the collectionPackage Com.crm.net.util;import Java.io.bufferedreader;import Java.io.bytearrayinputstream;import Java.io.ioexception;import Java.io.inputstreamreader;import Java.util.list;import Org.codehaus.jackson.jsonparseexception;import Org.codehaus.jackson.map.deserializationconfig;import Org.codehaus.jackson.map.jsonmappingexception;import Org.codeh
Objective:Jackson Common methods:Jackson is the usual two ways to handle the conversion between generic Java objects and JSON are the writevalueasstring () and ReadValue () methods of the Objectmapper class that can be implemented.However, if it is to be turned into a list collection of the specified generics, such as listCollection Type;To illustrate:If it is a listgettypefactory (). Constructparametrictype (List.class, User.class);If it is a hashmap
Workaround:1. There is an escape character in the JSON string, which can be replaced or the transfer character can be cleared directly after ToString.Reference:https://stackoverflow.com/questions/40986738/ spring-data-rest-no-string-argument-constructor-factory-method-to-deserialize/40986739http://blog.csdn.net/legend_x/article/details/31767083http://www.oschina.net/question/227902_163010https://stackoverflow.com/questions/40166309/ No-string-argument
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
1. On-Entity@JsonInclude (Include.non_null)Place the tag on the property, if the property is null, does not participate in serializationIf placed on top of a class, it works for all properties of the classInclude.Include.ALWAYS DefaultThe Include.non_default property is not serialized as the default valueInclude.non_empty property is empty ("") or null is not serializedInclude.non_null property is NULL not serialized2. On the CodeObjectmapper mapper = new Objectmapper ();Mapper.setserializationi
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.