Jackson, 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 Objectmapper object can be implemented. However, if you want to convert a complex type collection such as List<yourbean>, then you need to deserialize the collection type that is a generic of complex types.
If it is arraylist<yourbean> then use Objectmapper's Gettypefactory (). Constructparametrictype (Collectionclass, elementclasses);
If it is hashmap<string,yourbean> then Objectmapper gettypefactory (). Constructparametrictype (HashMap.class, String.class, Yourbean.class);
Public final Objectmapper mapper = new Objectmapper ();
public static void Main (string[] args) throws exception{
Javatype Javatype = Getcollectiontype (Arraylist.class, Yourbean.class);
list<yourbean> lst = (list<yourbean>) mapper.readvalue (jsonstring, Javatype);
}
/**
* Gets the collection type of the generic
* @param collection of Collectionclass generics
* @param elementclasses Element class
* @return Javatype Java type
* @since 1.0
*/
public static Javatype Getcollectiontype (class<?> collectionclass, Class<?> .... elementclasses) {
Return Mapper.gettypefactory (). Constructparametrictype (Collectionclass, elementclasses);
}
Jackson converts a JSON string into a generic list