Reprinted from: http://www.cnblogs.com/quanyongan/archive/2013/04/16/3024993.html
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);
1 public final Objectmapper mapper = new Objectmapper (); 2 3 public static void Main (string[] args) throws exception{ 4 javatype javatype = Getcollectiontype ( Arraylist.class, yourbean.class); 5 list<yourbean> lst = (list<yourbean>) mapper.readvalue (jsonstring, javatype); 6 } 7 /** 8 * Get generic collection type 9 * @param collectionclass Generic Collection Ten * @param elementclasses element class one * @return javatype java type * @since 1.0 13 * * Public static Javatype getcollectiontype (class<?> collectionclass, Class<?> ..... elementclasses) { mapper.gettypefactory (). Constructparametrictype (Collectionclass, elementclasses); + }
Jackson Data type Conversion