handling of Jackson anomaliesCategory: Java 2014-02-26 21:18 486 people read comments (0) Collection report
1. Null Conversion-Exception: [HTML] view plain copy Can not instantiate value of type [map type; class Java.util.HashMap, [Simpl E type, class java.lang.String]-> [Simple Type, Class Java.lang.String]] from JSON String; No single-string Constructor/factory method
Workaround, add in Objectmapper configuration: [HTML] view plain copy mapper.configure (DeserializationConfig.Feature.ACCEPT_ Empty_string_as_null_object, True);
2, escape character-exception: [HTML] view plain copy org.codehaus.jackson.JsonParseException:Illegal unquoted character ( Ctrl-char, Code 9): Has to is escaped using backslash to is included in string value at [source:java.io.stringreader@ 10cfc2e3; Line:1, column:2461]
Workaround, add in Objectmapper configuration: [HTML] view plain copy mapper.configure (Feature.allow_unquoted_control_chars, True ) ;
The application of Jackson in HTTP interface test environment Shang release: 2013-04-05 22:04 Category: Interface test, article classification, framework sharing reading: 1,614 views 3 reviews
Here's a quick introduction to Jackson: Jackson can easily and efficiently convert a JSON object into a Java object, or convert a Java object into a JSON object and an XML document. Jackson has several notable features: High performance, serialization and deserialization of complex objects and large data objects, showing better performance than similar toolkits such as Gson,json-lib, and powerful, binding all common classes in the JDK and Java Bean class. Collection,map and enum; no dependencies, no dependencies other than JDK, fully open source, and rich in documentation and user groups for self-study purposes.
In the process of testing the interface of HTTP requests, we need to be flexible and convenient to process HTTP request return data, make the JSON string deserialized into Java objects, so that we can easily verify the return data. How to try to use Jackson for deserialization, the content of a lot on the web, so here to repeat. I would like to focus on the points to be noted in the interface testing process and possible solutions to problems encountered.
Note Point 1: Use the Data object class used by developers as much as possible as the Mapper class when deserializing.
Typically, when a browser sends an HTTP request to the server to apply the request data, the client application relies on a server-side client package so that after the JSON data is deserialized, the Java object needed for the rendering of the VM template is formed. This allows us to test the HTTP interface, we only need to rely on the client jar package in our test application, we can easily use these objects to assemble our mapper.
Note Point 2: When a developer provides a data object class that is "bad", you need to create the Pojo class yourself, or use the JDK's native data object.
Objectmapper Initialization Configuration Code:
?