Jackson ( org.codehaus.jackson ) – Parse JSON Array String to List<T>

Jackson ( org.codehaus.jackson ) – Parse JSON Array String to List<T>

   DAO\JSONDAO.java
 
   package DAO;
 
   import java.io.IOException;
   import java.util.List;
 
   import org.codehaus.jackson.JsonGenerationException;
   import org.codehaus.jackson.map.JsonMappingException;
   import org.codehaus.jackson.map.ObjectMapper;
   import org.codehaus.jackson.map.SerializationConfig;
 
   import Entity.Inventory;
   import Entity.jsonexception;
 
   public class JSONDAO
   {
      … …
 
      public List<Inventory> getInventoryListByJArrayString(String JSONArray)
      {
         ObjectMapper mapper = new ObjectMapper();
 
         try
         {
            mapper.enable(SerializationConfig.Feature.INDENT_OUTPUT);
 
            return (mapper.readValue(JSONArray, mapper.getTypeFactory().constructCollectionType(List.class, Inventory.class)));
         }
         catch ( JsonGenerationException e )
         {
            e.printStackTrace();
         }
         catch ( JsonMappingException e )
         {
            e.printStackTrace();
         }
         catch ( IOException e )
         {
            e.printStackTrace();
         }
 
         return null;
      }
   }