title: Load an Object using Gson
body: <p>Forgive me if this is trivial or not possible but I'm having a Monday morning moment here.</p>
  
  <p>I'd like to create a method that implements some methods from the <code>Gson</code> library to loaded some settings Objects. Basically, I have a bunch of different settings objects but I don't want to habe to override the load method for each class to I'd like to have something like:</p>
  
  <pre><code>public class ConfigLoader {
      public static void main(final String[] args) {   
          final ConfigurationSettings loadedConfigSettigs =
              load("testSettings.json", ConfigurationSettings.class);
  
          final AlternativeConfigurationSettings alternativeConfigSettigs =
              load("testSettings2.json", AlternativeConfigurationSettings .class);
      }
  
      public T load(final InputStream inputStream, final Class&lt;T&gt; clazz) {
          try {
              if (inputStream != null) {
                  final Gson gson = new Gson();
                  final BufferedReader reader =
                      new BufferedReader(new InputStreamReader(inputStream));
                  return gson.fromJson(reader, clazz);
              }
          } catch (final Exception e) {
          }
          return null;
      }
  }
  </code></pre>
  
  <p>where I can pass in the <code>InputStream</code> and the class of the object I want to return. Is there a simple way to do this (I don't want to have to create a method for each Class I want to be able to load, nor do I want to have to create a specific loader for each class)?</p>